Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -125,22 +125,20 @@ def do_web_search(query: str) -> str:
|
|
125 |
summary_lines.append(
|
126 |
f"### Result {idx}: {title}\n\n"
|
127 |
f"{snippet}\n\n"
|
128 |
-
f"
|
129 |
f"---\n"
|
130 |
)
|
131 |
|
132 |
# ๋ชจ๋ธ์๊ฒ ๋ช
ํํ ์ง์นจ ์ถ๊ฐ
|
133 |
instructions = """
|
134 |
-
#
|
135 |
-
|
136 |
-
1.
|
137 |
-
2.
|
138 |
-
3. ์๋ต์ ์ค์ ์ถ์ฒ ๋งํฌ๋ฅผ ํฌํจํ์ธ์
|
139 |
-
4. ์ฌ๋ฌ ์ถ์ฒ์ ์ ๋ณด๋ฅผ ์ข
ํฉํ์ฌ ๋ต๋ณํ์ธ์
|
140 |
"""
|
141 |
|
142 |
search_results = instructions + "\n".join(summary_lines)
|
143 |
-
logger.info(f"
|
144 |
return search_results
|
145 |
|
146 |
except Exception as e:
|
@@ -500,13 +498,12 @@ def run(
|
|
500 |
ws_result = do_web_search(ws_query)
|
501 |
combined_system_msg += f"[Search top-20 Full Items Based on user prompt]\n{ws_result}\n\n"
|
502 |
# >>> ์ถ๊ฐ๋ ์๋ด ๋ฌธ๊ตฌ (๊ฒ์ ๊ฒฐ๊ณผ์ link ๋ฑ ์ถ์ฒ๋ฅผ ํ์ฉ)
|
503 |
-
combined_system_msg += "[
|
504 |
combined_system_msg += """
|
505 |
-
[
|
506 |
-
1.
|
507 |
-
2.
|
508 |
-
3.
|
509 |
-
4. ๋ต๋ณ ๋ง์ง๋ง์ "์ฐธ๊ณ ์๋ฃ:" ์น์
์ ์ถ๊ฐํ๊ณ ์ฌ์ฉํ ์ฃผ์ ์ถ์ฒ ๋งํฌ๋ฅผ ๋์ดํ์ธ์.
|
510 |
"""
|
511 |
else:
|
512 |
combined_system_msg += "[No valid keywords found, skipping WebSearch]\n\n"
|
@@ -544,7 +541,7 @@ def run(
|
|
544 |
|
545 |
streamer = TextIteratorStreamer(processor, timeout=30.0, skip_prompt=True, skip_special_tokens=True)
|
546 |
gen_kwargs = dict(
|
547 |
-
inputs,
|
548 |
streamer=streamer,
|
549 |
max_new_tokens=max_new_tokens,
|
550 |
)
|
@@ -559,7 +556,7 @@ def run(
|
|
559 |
|
560 |
except Exception as e:
|
561 |
logger.error(f"Error in run: {str(e)}")
|
562 |
-
yield f"
|
563 |
|
564 |
finally:
|
565 |
# ์์ ํ์ผ ์ญ์
|
@@ -581,12 +578,12 @@ def run(
|
|
581 |
|
582 |
|
583 |
##############################################################################
|
584 |
-
# ์์๋ค (
|
585 |
##############################################################################
|
586 |
examples = [
|
587 |
[
|
588 |
{
|
589 |
-
"text": "
|
590 |
"files": [
|
591 |
"assets/additional-examples/before.pdf",
|
592 |
"assets/additional-examples/after.pdf",
|
@@ -595,43 +592,43 @@ examples = [
|
|
595 |
],
|
596 |
[
|
597 |
{
|
598 |
-
"text": "
|
599 |
"files": ["assets/additional-examples/sample-csv.csv"],
|
600 |
}
|
601 |
],
|
602 |
[
|
603 |
{
|
604 |
-
"text": "
|
605 |
"files": ["assets/additional-examples/tmp.mp4"],
|
606 |
}
|
607 |
],
|
608 |
[
|
609 |
{
|
610 |
-
"text": "
|
611 |
"files": ["assets/additional-examples/maz.jpg"],
|
612 |
}
|
613 |
],
|
614 |
[
|
615 |
{
|
616 |
-
"text": "
|
617 |
"files": ["assets/additional-examples/pill1.png", "assets/additional-examples/pill2.png"],
|
618 |
}
|
619 |
],
|
620 |
[
|
621 |
{
|
622 |
-
"text": "
|
623 |
"files": ["assets/additional-examples/4.png"],
|
624 |
}
|
625 |
],
|
626 |
[
|
627 |
{
|
628 |
-
"text": "
|
629 |
"files": ["assets/additional-examples/2.png"],
|
630 |
}
|
631 |
],
|
632 |
[
|
633 |
{
|
634 |
-
"text": "
|
635 |
"files": [
|
636 |
"assets/sample-images/09-1.png",
|
637 |
"assets/sample-images/09-2.png",
|
@@ -641,32 +638,30 @@ examples = [
|
|
641 |
],
|
642 |
}
|
643 |
],
|
644 |
-
|
645 |
[
|
646 |
{
|
647 |
-
"text": "
|
648 |
"files": ["assets/additional-examples/barchart.png"],
|
649 |
}
|
650 |
],
|
651 |
[
|
652 |
{
|
653 |
-
"text": "
|
654 |
"files": ["assets/additional-examples/3.png"],
|
655 |
}
|
656 |
],
|
657 |
[
|
658 |
{
|
659 |
-
"text": "
|
660 |
"files": ["assets/sample-images/02.png"],
|
661 |
}
|
662 |
],
|
663 |
[
|
664 |
{
|
665 |
-
"text": "
|
666 |
"files": ["assets/sample-images/03.png"],
|
667 |
}
|
668 |
],
|
669 |
-
|
670 |
]
|
671 |
|
672 |
##############################################################################
|
@@ -772,80 +767,73 @@ title_html = """
|
|
772 |
<h1 align="center" style="margin-bottom: 0.2em; font-size: 1.6em;"> ๐ค Gemma3-R1984-27B </h1>
|
773 |
<p align="center" style="font-size:1.1em; color:#555;">
|
774 |
โ
Agentic AI Platform โ
Reasoning & Uncensored โ
Multimodal & VLM โ
Deep-Research & RAG <br>
|
775 |
-
Operates on an
|
776 |
@Based by 'MS Gemma-3-27b' / @Powered by 'MOUSE-II'(VIDRAFT)
|
777 |
</p>
|
778 |
"""
|
779 |
|
|
|
|
|
|
|
|
|
|
|
|
|
780 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
781 |
|
782 |
-
|
783 |
-
|
|
|
|
|
784 |
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
|
|
790 |
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
minimum=100,
|
801 |
-
maximum=8000,
|
802 |
-
step=50,
|
803 |
-
value=1000,
|
804 |
-
visible=False # ํ๋ฉด์์ ๊ฐ์ถค
|
805 |
-
)
|
806 |
-
|
807 |
-
web_search_text = gr.Textbox(
|
808 |
-
lines=1,
|
809 |
-
label="(Unused) Web Search Query",
|
810 |
-
placeholder="No direct input needed",
|
811 |
-
visible=False # ํ๋ฉด์์ ๊ฐ์ถค
|
812 |
-
)
|
813 |
-
|
814 |
-
# ์ฑํ
์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
815 |
-
chat = gr.ChatInterface(
|
816 |
-
fn=run,
|
817 |
-
type="messages",
|
818 |
-
chatbot=gr.Chatbot(type="messages", scale=1, allow_tags=["image"]),
|
819 |
-
textbox=gr.MultimodalTextbox(
|
820 |
-
file_types=[
|
821 |
-
".webp", ".png", ".jpg", ".jpeg", ".gif",
|
822 |
-
".mp4", ".csv", ".txt", ".pdf"
|
823 |
-
],
|
824 |
-
file_count="multiple",
|
825 |
-
autofocus=True
|
826 |
-
),
|
827 |
-
multimodal=True,
|
828 |
-
additional_inputs=[
|
829 |
-
system_prompt_box,
|
830 |
-
max_tokens_slider,
|
831 |
-
web_search_checkbox,
|
832 |
-
web_search_text,
|
833 |
],
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
|
|
|
|
|
|
|
|
|
|
847 |
|
|
|
|
|
|
|
|
|
848 |
|
849 |
if __name__ == "__main__":
|
850 |
-
#
|
851 |
-
|
|
|
125 |
summary_lines.append(
|
126 |
f"### Result {idx}: {title}\n\n"
|
127 |
f"{snippet}\n\n"
|
128 |
+
f"**Source**: [{displayed_link}]({link})\n\n"
|
129 |
f"---\n"
|
130 |
)
|
131 |
|
132 |
# ๋ชจ๋ธ์๊ฒ ๋ช
ํํ ์ง์นจ ์ถ๊ฐ
|
133 |
instructions = """
|
134 |
+
# Web Search Results
|
135 |
+
Below are the search results. Please refer to the title, snippet, and source link of each result when answering:
|
136 |
+
1. Cite the sources explicitly in your answer (e.g., "According to [Source Title](link)...").
|
137 |
+
2. Incorporate information from multiple sources.
|
|
|
|
|
138 |
"""
|
139 |
|
140 |
search_results = instructions + "\n".join(summary_lines)
|
141 |
+
logger.info(f"Processed {len(limited_organic)} search results")
|
142 |
return search_results
|
143 |
|
144 |
except Exception as e:
|
|
|
498 |
ws_result = do_web_search(ws_query)
|
499 |
combined_system_msg += f"[Search top-20 Full Items Based on user prompt]\n{ws_result}\n\n"
|
500 |
# >>> ์ถ๊ฐ๋ ์๋ด ๋ฌธ๊ตฌ (๊ฒ์ ๊ฒฐ๊ณผ์ link ๋ฑ ์ถ์ฒ๋ฅผ ํ์ฉ)
|
501 |
+
combined_system_msg += "[Note: Use the above search results and their links as sources when answering.]\n\n"
|
502 |
combined_system_msg += """
|
503 |
+
[Important Instructions]
|
504 |
+
1. Cite the sources found in the search results using markdown links, e.g., "[Source Title](link)".
|
505 |
+
2. Combine information from multiple sources in your answer.
|
506 |
+
3. At the end of your answer, add a "References:" section listing the key source links.
|
|
|
507 |
"""
|
508 |
else:
|
509 |
combined_system_msg += "[No valid keywords found, skipping WebSearch]\n\n"
|
|
|
541 |
|
542 |
streamer = TextIteratorStreamer(processor, timeout=30.0, skip_prompt=True, skip_special_tokens=True)
|
543 |
gen_kwargs = dict(
|
544 |
+
inputs=inputs,
|
545 |
streamer=streamer,
|
546 |
max_new_tokens=max_new_tokens,
|
547 |
)
|
|
|
556 |
|
557 |
except Exception as e:
|
558 |
logger.error(f"Error in run: {str(e)}")
|
559 |
+
yield f"Sorry, an error occurred: {str(e)}"
|
560 |
|
561 |
finally:
|
562 |
# ์์ ํ์ผ ์ญ์
|
|
|
578 |
|
579 |
|
580 |
##############################################################################
|
581 |
+
# ์์๋ค (๋ชจ๋ ์์ด๋ก)
|
582 |
##############################################################################
|
583 |
examples = [
|
584 |
[
|
585 |
{
|
586 |
+
"text": "Compare the contents of the two PDF files.",
|
587 |
"files": [
|
588 |
"assets/additional-examples/before.pdf",
|
589 |
"assets/additional-examples/after.pdf",
|
|
|
592 |
],
|
593 |
[
|
594 |
{
|
595 |
+
"text": "Summarize and analyze the contents of the CSV file.",
|
596 |
"files": ["assets/additional-examples/sample-csv.csv"],
|
597 |
}
|
598 |
],
|
599 |
[
|
600 |
{
|
601 |
+
"text": "Assume the role of a friendly and understanding girlfriend. Describe this video.",
|
602 |
"files": ["assets/additional-examples/tmp.mp4"],
|
603 |
}
|
604 |
],
|
605 |
[
|
606 |
{
|
607 |
+
"text": "Describe the cover and read the text on it.",
|
608 |
"files": ["assets/additional-examples/maz.jpg"],
|
609 |
}
|
610 |
],
|
611 |
[
|
612 |
{
|
613 |
+
"text": "I already have this supplement <image> and I plan to buy this product <image>. Are there any precautions when taking them together?",
|
614 |
"files": ["assets/additional-examples/pill1.png", "assets/additional-examples/pill2.png"],
|
615 |
}
|
616 |
],
|
617 |
[
|
618 |
{
|
619 |
+
"text": "Solve this integral.",
|
620 |
"files": ["assets/additional-examples/4.png"],
|
621 |
}
|
622 |
],
|
623 |
[
|
624 |
{
|
625 |
+
"text": "When was this ticket issued, and what is its price?",
|
626 |
"files": ["assets/additional-examples/2.png"],
|
627 |
}
|
628 |
],
|
629 |
[
|
630 |
{
|
631 |
+
"text": "Based on the sequence of these images, create a short story.",
|
632 |
"files": [
|
633 |
"assets/sample-images/09-1.png",
|
634 |
"assets/sample-images/09-2.png",
|
|
|
638 |
],
|
639 |
}
|
640 |
],
|
|
|
641 |
[
|
642 |
{
|
643 |
+
"text": "Write Python code using matplotlib to plot a bar chart that matches this image.",
|
644 |
"files": ["assets/additional-examples/barchart.png"],
|
645 |
}
|
646 |
],
|
647 |
[
|
648 |
{
|
649 |
+
"text": "Read the text in the image and write it out in Markdown format.",
|
650 |
"files": ["assets/additional-examples/3.png"],
|
651 |
}
|
652 |
],
|
653 |
[
|
654 |
{
|
655 |
+
"text": "What does this sign say?",
|
656 |
"files": ["assets/sample-images/02.png"],
|
657 |
}
|
658 |
],
|
659 |
[
|
660 |
{
|
661 |
+
"text": "Compare the two images and describe their similarities and differences.",
|
662 |
"files": ["assets/sample-images/03.png"],
|
663 |
}
|
664 |
],
|
|
|
665 |
]
|
666 |
|
667 |
##############################################################################
|
|
|
767 |
<h1 align="center" style="margin-bottom: 0.2em; font-size: 1.6em;"> ๐ค Gemma3-R1984-27B </h1>
|
768 |
<p align="center" style="font-size:1.1em; color:#555;">
|
769 |
โ
Agentic AI Platform โ
Reasoning & Uncensored โ
Multimodal & VLM โ
Deep-Research & RAG <br>
|
770 |
+
Operates on an NVIDIA A100 GPU as an independent local server, enhancing security and preventing information leakage.<br>
|
771 |
@Based by 'MS Gemma-3-27b' / @Powered by 'MOUSE-II'(VIDRAFT)
|
772 |
</p>
|
773 |
"""
|
774 |
|
775 |
+
# ์์ ๋ ์์คํ
ํ๋กฌํํธ: ์
๋ ฅ ์ธ์ด์ ๋ง์ถฐ ์๋ตํ๋๋ก ์ง์
|
776 |
+
system_prompt_box = gr.Textbox(
|
777 |
+
lines=3,
|
778 |
+
value="You are a deep thinking AI. Please respond in the same language as the input prompt. If the input is in English, answer in English. If it is in another language (e.g., Korean, Japanese), answer in that language using your full reasoning capabilities.",
|
779 |
+
visible=False # ํ๋ฉด์์ ๊ฐ์ถค
|
780 |
+
)
|
781 |
|
782 |
+
max_tokens_slider = gr.Slider(
|
783 |
+
label="Max New Tokens",
|
784 |
+
minimum=100,
|
785 |
+
maximum=8000,
|
786 |
+
step=50,
|
787 |
+
value=1000,
|
788 |
+
visible=False # ํ๋ฉด์์ ๊ฐ์ถค
|
789 |
+
)
|
790 |
|
791 |
+
web_search_checkbox = gr.Checkbox(
|
792 |
+
label="Deep Research",
|
793 |
+
value=False
|
794 |
+
)
|
795 |
|
796 |
+
web_search_text = gr.Textbox(
|
797 |
+
lines=1,
|
798 |
+
label="(Unused) Web Search Query",
|
799 |
+
placeholder="No direct input needed",
|
800 |
+
visible=False # ํ๋ฉด์์ ๊ฐ์ถค
|
801 |
+
)
|
802 |
|
803 |
+
# ์ฑํ
์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
804 |
+
chat = gr.ChatInterface(
|
805 |
+
fn=run,
|
806 |
+
type="messages",
|
807 |
+
chatbot=gr.Chatbot(type="messages", scale=1, allow_tags=["image"]),
|
808 |
+
textbox=gr.MultimodalTextbox(
|
809 |
+
file_types=[
|
810 |
+
".webp", ".png", ".jpg", ".jpeg", ".gif",
|
811 |
+
".mp4", ".csv", ".txt", ".pdf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
812 |
],
|
813 |
+
file_count="multiple",
|
814 |
+
autofocus=True
|
815 |
+
),
|
816 |
+
multimodal=True,
|
817 |
+
additional_inputs=[
|
818 |
+
system_prompt_box,
|
819 |
+
max_tokens_slider,
|
820 |
+
web_search_checkbox,
|
821 |
+
web_search_text,
|
822 |
+
],
|
823 |
+
stop_btn=False,
|
824 |
+
title='<a href="https://discord.gg/openfreeai" target="_blank">https://discord.gg/openfreeai</a>',
|
825 |
+
examples=examples,
|
826 |
+
run_examples_on_click=False,
|
827 |
+
cache_examples=False,
|
828 |
+
css_paths=None,
|
829 |
+
delete_cache=(1800, 1800),
|
830 |
+
)
|
831 |
|
832 |
+
# ์์ ์น์
- ์ด๋ฏธ ChatInterface์ examples๊ฐ ์ค์ ๋์ด ์์ผ๋ฏ๋ก ์ฌ๊ธฐ์๋ ์ค๋ช
๋ง ํ์
|
833 |
+
with gr.Row(elem_id="examples_row"):
|
834 |
+
with gr.Column(scale=12, elem_id="examples_container"):
|
835 |
+
gr.Markdown("### Example Inputs (click to load)")
|
836 |
|
837 |
if __name__ == "__main__":
|
838 |
+
# Run locally
|
839 |
+
chat.launch()
|