openfree commited on
Commit
e828578
ยท
verified ยท
1 Parent(s): 9975586

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -76
app.py CHANGED
@@ -142,6 +142,7 @@ def pdf_to_markdown(pdf_path: str) -> str:
142
  page_text = page.extract_text() or ""
143
  page_text = page_text.strip()
144
  if page_text:
 
145
  if len(page_text) > MAX_CONTENT_CHARS // max_pages:
146
  page_text = page_text[:MAX_CONTENT_CHARS // max_pages] + "...(truncated)"
147
  text_chunks.append(f"## Page {page_num+1}\n\n{page_text}\n")
@@ -277,6 +278,7 @@ def process_interleaved_images(message: dict) -> list[dict]:
277
  elif part.strip():
278
  content.append({"type": "text", "text": part.strip()})
279
  else:
 
280
  if isinstance(part, str) and part != "<image>":
281
  content.append({"type": "text", "text": part})
282
  return content
@@ -329,6 +331,7 @@ def process_new_user_message(message: dict) -> list[dict]:
329
 
330
  if "<image>" in message["text"] and image_files:
331
  interleaved_content = process_interleaved_images({"text": message["text"], "files": image_files})
 
332
  if content_list and content_list[0]["type"] == "text":
333
  content_list = content_list[1:]
334
  return interleaved_content + content_list
@@ -388,6 +391,7 @@ def run(
388
  try:
389
  combined_system_msg = ""
390
 
 
391
  if system_prompt.strip():
392
  combined_system_msg += f"[System Prompt]\n{system_prompt.strip()}\n\n"
393
 
@@ -467,7 +471,6 @@ examples = [
467
  [
468
  {
469
  "text": "๋‘ PDF ํŒŒ์ผ ๋‚ด์šฉ์„ ๋น„๊ตํ•˜๋ผ.",
470
- "files": ["assets/additional-examples/pdf.pdf"],
471
  "files": [
472
  "assets/additional-examples/before.pdf",
473
  "assets/additional-examples/after.pdf",
@@ -562,7 +565,7 @@ examples = [
562
 
563
 
564
  ##############################################################################
565
- # Gradio UI (Blocks) ๊ตฌ์„ฑ
566
  ##############################################################################
567
  css = """
568
  body {
@@ -584,8 +587,8 @@ body {
584
  color: #333;
585
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
586
  }
587
- .fillable {
588
- width: 95% !important;
589
  max-width: unset !important;
590
  }
591
  #examples_container {
@@ -595,12 +598,6 @@ body {
595
  #examples_row {
596
  justify-content: center;
597
  }
598
- .sidebar {
599
- background: rgba(255, 255, 255, 0.98);
600
- border-radius: 10px;
601
- padding: 20px;
602
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
603
- }
604
  button, .btn {
605
  background: linear-gradient(90deg, #ff8a00, #e52e71);
606
  border: none;
@@ -628,70 +625,61 @@ title_html = """
628
  with gr.Blocks(css=css, title="Vidraft-G3-27B ") as demo:
629
  gr.Markdown(title_html)
630
 
631
- with gr.Row():
632
- # Left Sidebar
633
- with gr.Column(scale=3, variant="panel"):
634
- gr.Markdown("### Menu / Options")
635
- with gr.Row():
636
- web_search_checkbox = gr.Checkbox(
637
- label="Web Search",
638
- value=False,
639
- info="Check to enable a Deep Research(auto keywords) before the chat reply"
640
- )
641
- web_search_text = gr.Textbox(
642
- lines=1,
643
- label="(Unused) Web Search Query",
644
- placeholder="No direct input needed"
645
- )
646
-
647
- gr.Markdown("---")
648
- gr.Markdown("#### System Prompt")
649
- system_prompt_box = gr.Textbox(
650
- lines=3,
651
- value=(
652
- "You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. Please answer in korean."
653
- ),
654
- )
655
 
656
- max_tokens_slider = gr.Slider(
657
- label="Max New Tokens",
658
- minimum=100,
659
- maximum=8000,
660
- step=50,
661
- value=2000, # GPU ๋ฉ”๋ชจ๋ฆฌ ์ ˆ์•ฝ ์œ„ํ•ด ๊ธฐ๋ณธ๊ฐ’ ์•ฝ๊ฐ„ ์ถ•์†Œ
662
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
663
 
664
- gr.Markdown("<br><br>")
665
-
666
- # Main ChatInterface
667
- with gr.Column(scale=7):
668
- chat = gr.ChatInterface(
669
- fn=run,
670
- type="messages",
671
- chatbot=gr.Chatbot(type="messages", scale=1, allow_tags=["image"]),
672
- textbox=gr.MultimodalTextbox(
673
- file_types=[
674
- ".webp", ".png", ".jpg", ".jpeg", ".gif",
675
- ".mp4", ".csv", ".txt", ".pdf"
676
- ],
677
- file_count="multiple",
678
- autofocus=True
679
- ),
680
- multimodal=True,
681
- additional_inputs=[
682
- system_prompt_box,
683
- max_tokens_slider,
684
- web_search_checkbox,
685
- web_search_text,
686
- ],
687
- stop_btn=False,
688
- title="https://discord.gg/openfreeai",
689
- examples=examples,
690
- run_examples_on_click=False,
691
- cache_examples=False,
692
- css_paths=None,
693
- delete_cache=(1800, 1800),
694
- )
695
 
696
  with gr.Row(elem_id="examples_row"):
697
  with gr.Column(scale=12, elem_id="examples_container"):
@@ -702,8 +690,7 @@ with gr.Blocks(css=css, title="Vidraft-G3-27B ") as demo:
702
  cache_examples=False
703
  )
704
 
705
- if __name__ == "__main__":
706
- # share=True ์‹œ HF Spaces์—์„œ ๊ฒฝ๊ณ  ๋ฐœ์ƒ - ๋กœ์ปฌ์—์„œ๋งŒ ๋™์ž‘
707
- # demo.launch(share=True)
708
- demo.launch()
709
 
 
 
 
 
142
  page_text = page.extract_text() or ""
143
  page_text = page_text.strip()
144
  if page_text:
145
+ # ํŽ˜์ด์ง€๋ณ„ ์ตœ๋Œ€์น˜ ์ž˜๋ผ์„œ ์‚ฌ์šฉ
146
  if len(page_text) > MAX_CONTENT_CHARS // max_pages:
147
  page_text = page_text[:MAX_CONTENT_CHARS // max_pages] + "...(truncated)"
148
  text_chunks.append(f"## Page {page_num+1}\n\n{page_text}\n")
 
278
  elif part.strip():
279
  content.append({"type": "text", "text": part.strip()})
280
  else:
281
+ # ๋นˆ ๋ฌธ์ž์—ด๋„ content์— ์ถ”๊ฐ€๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์กฐ์ •
282
  if isinstance(part, str) and part != "<image>":
283
  content.append({"type": "text", "text": part})
284
  return content
 
331
 
332
  if "<image>" in message["text"] and image_files:
333
  interleaved_content = process_interleaved_images({"text": message["text"], "files": image_files})
334
+ # ์ด๋ฏธ text ๋ณธ๋ฌธ์— <image>๊ฐ€ ํฌํ•จ๋œ ๊ฒฝ์šฐ, ์ค‘๋ณต ์ฒ˜๋ฆฌ๋ฅผ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š” ์‹œ ์กฐ์ •
335
  if content_list and content_list[0]["type"] == "text":
336
  content_list = content_list[1:]
337
  return interleaved_content + content_list
 
391
  try:
392
  combined_system_msg = ""
393
 
394
+ # ๋‚ด๋ถ€์ ์œผ๋กœ๋งŒ ์‚ฌ์šฉ (UI์—์„œ๋Š” ๋ณด์ด์ง€ ์•Š์Œ)
395
  if system_prompt.strip():
396
  combined_system_msg += f"[System Prompt]\n{system_prompt.strip()}\n\n"
397
 
 
471
  [
472
  {
473
  "text": "๋‘ PDF ํŒŒ์ผ ๋‚ด์šฉ์„ ๋น„๊ตํ•˜๋ผ.",
 
474
  "files": [
475
  "assets/additional-examples/before.pdf",
476
  "assets/additional-examples/after.pdf",
 
565
 
566
 
567
  ##############################################################################
568
+ # Gradio UI (Blocks) ๊ตฌ์„ฑ (์ขŒ์ธก ์‚ฌ์ด๋“œ ๋ฉ”๋‰ด ์—†์ด ์ „์ฒดํ™”๋ฉด ์ฑ„ํŒ…)
569
  ##############################################################################
570
  css = """
571
  body {
 
587
  color: #333;
588
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
589
  }
590
+ .fillable {
591
+ width: 95% !important;
592
  max-width: unset !important;
593
  }
594
  #examples_container {
 
598
  #examples_row {
599
  justify-content: center;
600
  }
 
 
 
 
 
 
601
  button, .btn {
602
  background: linear-gradient(90deg, #ff8a00, #e52e71);
603
  border: none;
 
625
  with gr.Blocks(css=css, title="Vidraft-G3-27B ") as demo:
626
  gr.Markdown(title_html)
627
 
628
+ # ์›น์„œ์น˜ ์˜ต์…˜์€ ํ™”๋ฉด์— ํ‘œ์‹œ (ํ•˜์ง€๋งŒ ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ, ํ† ํฐ ์Šฌ๋ผ์ด๋” ๋“ฑ์€ ๊ฐ์ถค)
629
+ web_search_checkbox = gr.Checkbox(
630
+ label="Use Web Search (์ž๋™ ํ‚ค์›Œ๋“œ ์ถ”์ถœ)",
631
+ value=False
632
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633
 
634
+ # ๋‚ด๋ถ€์ ์œผ๋กœ ์“ฐ์ด์ง€๋งŒ ํ™”๋ฉด์—๋Š” ๋…ธ์ถœ๋˜์ง€ ์•Š๋„๋ก ์„ค์ •
635
+ system_prompt_box = gr.Textbox(
636
+ lines=3,
637
+ value="You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. Please answer in Korean.",
638
+ visible=False # ํ™”๋ฉด์—์„œ ๊ฐ์ถค
639
+ )
640
+ max_tokens_slider = gr.Slider(
641
+ label="Max New Tokens",
642
+ minimum=100,
643
+ maximum=8000,
644
+ step=50,
645
+ value=2000,
646
+ visible=False # ํ™”๋ฉด์—์„œ ๊ฐ์ถค
647
+ )
648
+ web_search_text = gr.Textbox(
649
+ lines=1,
650
+ label="(Unused) Web Search Query",
651
+ placeholder="No direct input needed",
652
+ visible=False # ํ™”๋ฉด์—์„œ ๊ฐ์ถค
653
+ )
654
 
655
+ # ์ฑ„ํŒ… ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ™”๋ฉด ์ „์ฒด ํญ์œผ๋กœ ์‚ฌ์šฉ
656
+ chat = gr.ChatInterface(
657
+ fn=run,
658
+ type="messages",
659
+ chatbot=gr.Chatbot(type="messages", scale=1, allow_tags=["image"]),
660
+ textbox=gr.MultimodalTextbox(
661
+ file_types=[
662
+ ".webp", ".png", ".jpg", ".jpeg", ".gif",
663
+ ".mp4", ".csv", ".txt", ".pdf"
664
+ ],
665
+ file_count="multiple",
666
+ autofocus=True
667
+ ),
668
+ multimodal=True,
669
+ additional_inputs=[
670
+ system_prompt_box,
671
+ max_tokens_slider,
672
+ web_search_checkbox,
673
+ web_search_text,
674
+ ],
675
+ stop_btn=False,
676
+ title="https://discord.gg/openfreeai",
677
+ examples=examples,
678
+ run_examples_on_click=False,
679
+ cache_examples=False,
680
+ css_paths=None,
681
+ delete_cache=(1800, 1800),
682
+ )
 
 
 
683
 
684
  with gr.Row(elem_id="examples_row"):
685
  with gr.Column(scale=12, elem_id="examples_container"):
 
690
  cache_examples=False
691
  )
692
 
 
 
 
 
693
 
694
+ if __name__ == "__main__":
695
+ # ๋กœ์ปฌ์—์„œ๋งŒ ์‹คํ–‰ ์‹œ
696
+ demo.launch()