Asilbek14 commited on
Commit
4e13938
Β·
verified Β·
1 Parent(s): 04dad65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
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": translated}
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
- # 🌍 Zephyr-7B with Multilingual Support
83
- - πŸ’¬ Normal chat powered by **Zephyr-7B**
84
- - 🌐 Translation powered by **M2M100** (auto-detects non-English or "translate" requests)
 
 
 
 
 
 
85
  """
86
  )
87
 
88
- chatbot = gr.Chatbot(type="messages", height=500, show_copy_button=True, label="Chat")
 
 
 
 
 
89
 
90
  with gr.Row():
91
- msg = gr.Textbox(label="πŸ’¬ Message", placeholder="Type your message…", scale=6)
92
- send_btn = gr.Button("πŸš€", variant="primary", scale=1)
93
- clear_btn = gr.Button("🧹", scale=1)
 
 
 
 
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()