openfree commited on
Commit
cbc6c4f
ยท
verified ยท
1 Parent(s): d0b06a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -29
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"**์ถœ์ฒ˜**: [{displayed_link}]({link})\n\n"
145
  f"---\n"
146
  )
147
 
148
  instructions = """
149
- # ์›น ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ / Web Search Results
150
 
151
- ์•„๋ž˜๋Š” ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค. ์งˆ๋ฌธ์— ๋‹ต๋ณ€ํ•  ๋•Œ ์ด ์ •๋ณด๋ฅผ ํ™œ์šฉํ•˜์„ธ์š”:
152
  Below are the search results. Use this information when answering the question:
153
 
154
- 1. ๊ฐ ๊ฒฐ๊ณผ์˜ ์ œ๋ชฉ, ๋‚ด์šฉ, ์ถœ์ฒ˜ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š” / Reference the title, content, and source links
155
- 2. ๋‹ต๋ณ€์— ๊ด€๋ จ ์ •๋ณด์˜ ์ถœ์ฒ˜๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ธ์šฉํ•˜์„ธ์š” / Explicitly cite relevant sources
156
- 3. ์‘๋‹ต์— ์‹ค์ œ ์ถœ์ฒ˜ ๋งํฌ๋ฅผ ํฌํ•จํ•˜์„ธ์š” / Include actual source links in response
157
- 4. ์—ฌ๋Ÿฌ ์ถœ์ฒ˜์˜ ์ •๋ณด๋ฅผ ์ข…ํ•ฉํ•˜์—ฌ ๋‹ต๋ณ€ํ•˜์„ธ์š” / Synthesize information from multiple sources
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"์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
483
 
484
  finally:
485
  # ๋ฉ”๋ชจ๋ฆฌ ์ •๋ฆฌ
@@ -496,7 +495,7 @@ examples = [
496
 
497
  [
498
  {
499
- "text": "๋‘ PDF ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ๋น„๊ต ๋ถ„์„ํ•ด์ฃผ์„ธ์š”.",
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 (ํ…์ŠคํŠธ ์ „์šฉ) </h1>
549
  <p align="center" style="font-size:1.1em; color:#555;">
550
- โœ…์—์ด์ „ํ‹ฑ AI ํ”Œ๋žซํผ โœ…์ถ”๋ก  ๋ฐ ๋ถ„์„ โœ…ํ…์ŠคํŠธ ๋ถ„์„ โœ…์‹ฌ์ธต ์—ฐ๊ตฌ & RAG <br>
551
- โœ…๋ฌธ์„œ ์ฒ˜๋ฆฌ (PDF, CSV, TXT) โœ…์›น ๊ฒ€์ƒ‰ ํ†ตํ•ฉ โœ…ํ•œ๊ธ€/์˜์–ด ์ง€์›<br>
552
- โœ…'NVIDIA L40s / A100(ZeroGPU) GPU'์—์„œ ๋…๋ฆฝ ๋กœ์ปฌ ์„œ๋ฒ„๋กœ ์ž‘๋™<br>
553
- @๋ชจ๋ธ ์ €์žฅ์†Œ: VIDraft/Gemma-3-R1984-1B, @๊ธฐ๋ฐ˜: 'Google Gemma-3-1b'
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("๊ณ ๊ธ‰ ์„ค์ •", open=False):
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="""๋‹น์‹ ์€ ์‹ฌ์ธต์ ์ธ ์‚ฌ๊ณ ๋ฅผ ํ•˜๋Š” AI ์–ด์‹œ์Šคํ„ดํŠธ์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ ์ง€์นจ์„ ๋”ฐ๋ผ์ฃผ์„ธ์š”:
579
-
580
- 1. **์–ธ์–ด**: ์‚ฌ์šฉ์ž๊ฐ€ ํ•œ๊ธ€๋กœ ์งˆ๋ฌธํ•˜๋ฉด ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋‹ต๋ณ€ํ•˜์„ธ์š”. ์˜์–ด๋กœ ์งˆ๋ฌธํ•˜๋ฉด ์˜์–ด๋กœ ๋‹ต๋ณ€ํ•˜์„ธ์š”.
581
- 2. **๋‹ต๋ณ€ ๊ธธ์ด**: ์ถฉ๋ถ„ํžˆ ์ƒ์„ธํ•˜๊ณ  ํ’๋ถ€ํ•œ ๋‹ต๋ณ€์„ ์ œ๊ณตํ•˜์„ธ์š”. ์ตœ์†Œ 3-5๊ฐœ ๋ฌธ๋‹จ์œผ๋กœ ๊ตฌ์„ฑ๋œ ๋‹ต๋ณ€์„ ์ž‘์„ฑํ•˜์„ธ์š”.
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()