Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
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 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
663 |
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
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()
|