Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,7 @@ TOP_P_DEFAULT = 0.95
|
|
19 |
client = InferenceClient(MODEL_REPO)
|
20 |
translator = pipeline("translation", model=TRANSLATOR_MODEL)
|
21 |
|
|
|
22 |
# ---------------- HELPERS ----------------
|
23 |
def is_translation_request(message: str) -> bool:
|
24 |
"""
|
@@ -38,9 +39,10 @@ def stream_response(message, chat_history, system_message, max_tokens, temperatu
|
|
38 |
if is_translation_request(message):
|
39 |
try:
|
40 |
translated = translator(message, src_lang="auto", tgt_lang="en")[0]["translation_text"]
|
|
|
41 |
return "", chat_history + [
|
42 |
{"role": "user", "content": message},
|
43 |
-
{"role": "assistant", "content":
|
44 |
]
|
45 |
except Exception as e:
|
46 |
return "", chat_history + [
|
@@ -79,20 +81,35 @@ def stream_response(message, chat_history, system_message, max_tokens, temperatu
|
|
79 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="pink")) as demo:
|
80 |
gr.Markdown(
|
81 |
"""
|
82 |
-
#
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
"""
|
86 |
)
|
87 |
|
88 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
with gr.Row():
|
91 |
-
msg = gr.Textbox(
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
with gr.Accordion("βοΈ Settings", open=False):
|
96 |
system_prompt = gr.Textbox(label="System Prompt", value=SYSTEM_PROMPT_DEFAULT, lines=3)
|
97 |
response_style = gr.Dropdown(
|
98 |
["Concise", "Detailed", "Essay"], value="Concise", label="Response Style"
|
@@ -114,5 +131,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="pink"))
|
|
114 |
)
|
115 |
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
116 |
|
|
|
|
|
|
|
117 |
if __name__ == "__main__":
|
118 |
-
demo.launch()
|
|
|
19 |
client = InferenceClient(MODEL_REPO)
|
20 |
translator = pipeline("translation", model=TRANSLATOR_MODEL)
|
21 |
|
22 |
+
|
23 |
# ---------------- HELPERS ----------------
|
24 |
def is_translation_request(message: str) -> bool:
|
25 |
"""
|
|
|
39 |
if is_translation_request(message):
|
40 |
try:
|
41 |
translated = translator(message, src_lang="auto", tgt_lang="en")[0]["translation_text"]
|
42 |
+
response = f"π **Translation β English:**\n\n{translated}"
|
43 |
return "", chat_history + [
|
44 |
{"role": "user", "content": message},
|
45 |
+
{"role": "assistant", "content": response}
|
46 |
]
|
47 |
except Exception as e:
|
48 |
return "", chat_history + [
|
|
|
81 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="pink")) as demo:
|
82 |
gr.Markdown(
|
83 |
"""
|
84 |
+
# π€ Zephyr-7B Chat + π Translator
|
85 |
+
Welcome! This app combines **Zephyr-7B** (for smart chat) with **M2M100** (for multilingual translation).
|
86 |
+
|
87 |
+
**How to use:**
|
88 |
+
- π¬ Ask *anything* β Zephyr will reply.
|
89 |
+
- π Paste non-English text or say "translate" β auto translation into English.
|
90 |
+
- βοΈ Adjust settings in the panel if you want different styles.
|
91 |
+
|
92 |
+
---
|
93 |
"""
|
94 |
)
|
95 |
|
96 |
+
chatbot = gr.Chatbot(
|
97 |
+
type="messages",
|
98 |
+
height=500,
|
99 |
+
show_copy_button=True,
|
100 |
+
label="Chat Assistant"
|
101 |
+
)
|
102 |
|
103 |
with gr.Row():
|
104 |
+
msg = gr.Textbox(
|
105 |
+
label="π¬ Your Message",
|
106 |
+
placeholder="Type here and press Enter or click π",
|
107 |
+
scale=6
|
108 |
+
)
|
109 |
+
send_btn = gr.Button("π Send", variant="primary", scale=1)
|
110 |
+
clear_btn = gr.Button("π§Ή Clear Chat", scale=1)
|
111 |
|
112 |
+
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
113 |
system_prompt = gr.Textbox(label="System Prompt", value=SYSTEM_PROMPT_DEFAULT, lines=3)
|
114 |
response_style = gr.Dropdown(
|
115 |
["Concise", "Detailed", "Essay"], value="Concise", label="Response Style"
|
|
|
131 |
)
|
132 |
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
133 |
|
134 |
+
gr.Markdown("---")
|
135 |
+
gr.Markdown("π Built with β€οΈ using [Zephyr-7B](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta) & [M2M100](https://huggingface.co/facebook/m2m100_418M).")
|
136 |
+
|
137 |
if __name__ == "__main__":
|
138 |
+
demo.launch()
|