Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -141,20 +141,19 @@ def do_web_search(query: str) -> str:
|
|
141 |
summary_lines.append(
|
142 |
f"### Result {idx}: {title}\n\n"
|
143 |
f"{snippet}\n\n"
|
144 |
-
f"
|
145 |
f"---\n"
|
146 |
)
|
147 |
|
148 |
instructions = """
|
149 |
-
#
|
150 |
|
151 |
-
์๋๋ ๊ฒ์ ๊ฒฐ๊ณผ์
๋๋ค. ์ง๋ฌธ์ ๋ต๋ณํ ๋ ์ด ์ ๋ณด๋ฅผ ํ์ฉํ์ธ์:
|
152 |
Below are the search results. Use this information when answering the question:
|
153 |
|
154 |
-
1.
|
155 |
-
2.
|
156 |
-
3.
|
157 |
-
4.
|
158 |
"""
|
159 |
|
160 |
search_results = instructions + "\n".join(summary_lines)
|
@@ -364,8 +363,8 @@ def _model_gen_with_oom_catch(**kwargs):
|
|
364 |
model.generate(**kwargs)
|
365 |
except torch.cuda.OutOfMemoryError:
|
366 |
raise RuntimeError(
|
367 |
-
"[OutOfMemoryError] GPU
|
368 |
-
"Max New Tokens
|
369 |
)
|
370 |
finally:
|
371 |
clear_cuda_cache()
|
@@ -479,7 +478,7 @@ def run(
|
|
479 |
|
480 |
except Exception as e:
|
481 |
logger.error(f"Error in run: {str(e)}")
|
482 |
-
yield f"
|
483 |
|
484 |
finally:
|
485 |
# ๋ฉ๋ชจ๋ฆฌ ์ ๋ฆฌ
|
@@ -496,7 +495,7 @@ examples = [
|
|
496 |
|
497 |
[
|
498 |
{
|
499 |
-
"text": "
|
500 |
"files": [
|
501 |
"assets/additional-examples/before.pdf",
|
502 |
"assets/additional-examples/after.pdf",
|
@@ -545,43 +544,43 @@ button:hover, .btn:hover {
|
|
545 |
"""
|
546 |
|
547 |
title_html = """
|
548 |
-
<h1 align="center" style="margin-bottom: 0.2em; font-size: 1.6em;"> ๐ค Gemma3-R1984-1B (
|
549 |
<p align="center" style="font-size:1.1em; color:#555;">
|
550 |
-
|
551 |
-
|
552 |
-
โ
'NVIDIA L40s / A100(ZeroGPU) GPU'
|
553 |
-
|
554 |
</p>
|
555 |
"""
|
556 |
|
557 |
with gr.Blocks(css=css, title="Gemma3-R1984-1B") as demo:
|
558 |
gr.Markdown(title_html)
|
559 |
|
560 |
-
with gr.Accordion("
|
561 |
web_search_checkbox = gr.Checkbox(
|
562 |
-
label="Deep Research (
|
563 |
value=False
|
564 |
)
|
565 |
|
566 |
max_tokens_slider = gr.Slider(
|
567 |
-
label="
|
568 |
minimum=100,
|
569 |
maximum=8000,
|
570 |
step=50,
|
571 |
value=2048,
|
572 |
-
info="
|
573 |
)
|
574 |
|
575 |
system_prompt_box = gr.Textbox(
|
576 |
lines=5,
|
577 |
-
label="
|
578 |
-
value="""
|
579 |
-
|
580 |
-
1.
|
581 |
-
2.
|
582 |
-
3.
|
583 |
-
4.
|
584 |
-
5.
|
585 |
)
|
586 |
|
587 |
web_search_text = gr.Textbox(
|
@@ -618,7 +617,7 @@ with gr.Blocks(css=css, title="Gemma3-R1984-1B") as demo:
|
|
618 |
|
619 |
with gr.Row(elem_id="examples_row"):
|
620 |
with gr.Column(scale=12, elem_id="examples_container"):
|
621 |
-
gr.Markdown("###
|
622 |
|
623 |
if __name__ == "__main__":
|
624 |
demo.launch()
|
|
|
141 |
summary_lines.append(
|
142 |
f"### Result {idx}: {title}\n\n"
|
143 |
f"{snippet}\n\n"
|
144 |
+
f"**Source**: [{displayed_link}]({link})\n\n"
|
145 |
f"---\n"
|
146 |
)
|
147 |
|
148 |
instructions = """
|
149 |
+
# Web Search Results
|
150 |
|
|
|
151 |
Below are the search results. Use this information when answering the question:
|
152 |
|
153 |
+
1. Reference the title, content, and source links from each result
|
154 |
+
2. Explicitly cite relevant sources in your response
|
155 |
+
3. Include actual source links in your response
|
156 |
+
4. Synthesize information from multiple sources when answering
|
157 |
"""
|
158 |
|
159 |
search_results = instructions + "\n".join(summary_lines)
|
|
|
363 |
model.generate(**kwargs)
|
364 |
except torch.cuda.OutOfMemoryError:
|
365 |
raise RuntimeError(
|
366 |
+
"[OutOfMemoryError] GPU memory insufficient. "
|
367 |
+
"Please reduce Max New Tokens or shorten the prompt length."
|
368 |
)
|
369 |
finally:
|
370 |
clear_cuda_cache()
|
|
|
478 |
|
479 |
except Exception as e:
|
480 |
logger.error(f"Error in run: {str(e)}")
|
481 |
+
yield f"Sorry, an error occurred: {str(e)}"
|
482 |
|
483 |
finally:
|
484 |
# ๋ฉ๋ชจ๋ฆฌ ์ ๋ฆฌ
|
|
|
495 |
|
496 |
[
|
497 |
{
|
498 |
+
"text": "Please compare and analyze the content of these two PDF files.",
|
499 |
"files": [
|
500 |
"assets/additional-examples/before.pdf",
|
501 |
"assets/additional-examples/after.pdf",
|
|
|
544 |
"""
|
545 |
|
546 |
title_html = """
|
547 |
+
<h1 align="center" style="margin-bottom: 0.2em; font-size: 1.6em;"> ๐ค Gemma3-R1984-1B (Text-Only) </h1>
|
548 |
<p align="center" style="font-size:1.1em; color:#555;">
|
549 |
+
โ
Agentic AI Platform โ
Reasoning & Analysis โ
Text Analysis โ
Deep Research & RAG <br>
|
550 |
+
โ
Document Processing (PDF, CSV, TXT) โ
Web Search Integration โ
Korean/English Support<br>
|
551 |
+
โ
Running on Independent Local Server with 'NVIDIA L40s / A100(ZeroGPU) GPU'<br>
|
552 |
+
@Model Repository: VIDraft/Gemma-3-R1984-1B, @Based on: 'Google Gemma-3-1b'
|
553 |
</p>
|
554 |
"""
|
555 |
|
556 |
with gr.Blocks(css=css, title="Gemma3-R1984-1B") as demo:
|
557 |
gr.Markdown(title_html)
|
558 |
|
559 |
+
with gr.Accordion("Advanced Settings", open=False):
|
560 |
web_search_checkbox = gr.Checkbox(
|
561 |
+
label="Deep Research (Enable Web Search)",
|
562 |
value=False
|
563 |
)
|
564 |
|
565 |
max_tokens_slider = gr.Slider(
|
566 |
+
label="Max Tokens (Response Length)",
|
567 |
minimum=100,
|
568 |
maximum=8000,
|
569 |
step=50,
|
570 |
value=2048,
|
571 |
+
info="Increase this value for longer responses"
|
572 |
)
|
573 |
|
574 |
system_prompt_box = gr.Textbox(
|
575 |
lines=5,
|
576 |
+
label="System Prompt",
|
577 |
+
value="""You are an AI assistant that performs deep thinking. Please follow these guidelines:
|
578 |
+
|
579 |
+
1. **Language**: If the user asks in Korean, you must answer in Korean. If they ask in English, answer in English.
|
580 |
+
2. **Response Length**: Provide sufficiently detailed and rich responses. Write responses with at least 3-5 paragraphs.
|
581 |
+
3. **Analysis Method**: Thoroughly analyze problems and provide accurate solutions through systematic reasoning processes.
|
582 |
+
4. **Structure**: Organize responses with clear structure, using numbers or bullet points when necessary.
|
583 |
+
5. **Examples and Explanations**: Include specific examples and detailed explanations whenever possible."""
|
584 |
)
|
585 |
|
586 |
web_search_text = gr.Textbox(
|
|
|
617 |
|
618 |
with gr.Row(elem_id="examples_row"):
|
619 |
with gr.Column(scale=12, elem_id="examples_container"):
|
620 |
+
gr.Markdown("### Example Inputs (Click to Load)")
|
621 |
|
622 |
if __name__ == "__main__":
|
623 |
demo.launch()
|