Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from gtts import gTTS
|
|
@@ -19,9 +18,16 @@ def respond(message, history):
|
|
| 19 |
prompt += f"<|user|> {user_msg}\n<|assistant|> {bot_msg}\n"
|
| 20 |
prompt += f"<|user|> {message}\n<|assistant|>"
|
| 21 |
|
| 22 |
-
response = client.text_generation(
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
| 25 |
history.append((message, response))
|
| 26 |
audio_path = speak_text(response)
|
| 27 |
return history, history, audio_path
|
|
@@ -29,14 +35,16 @@ def respond(message, history):
|
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
gr.Markdown("# Sambit AI 🤖")
|
| 31 |
chatbot = gr.Chatbot([], label="Chat with AI", type="messages")
|
| 32 |
-
msg = gr.Textbox(label="Type your message here")
|
| 33 |
audio_output = gr.Audio(label="AI Voice", interactive=False)
|
| 34 |
|
| 35 |
-
clear = gr.Button("Clear Chat")
|
| 36 |
|
| 37 |
state = gr.State([])
|
| 38 |
|
| 39 |
msg.submit(respond, [msg, state], [chatbot, state, audio_output])
|
| 40 |
clear.click(lambda: ([], [], None), None, [chatbot, state, audio_output])
|
| 41 |
|
|
|
|
| 42 |
demo.launch()
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
from gtts import gTTS
|
|
|
|
| 18 |
prompt += f"<|user|> {user_msg}\n<|assistant|> {bot_msg}\n"
|
| 19 |
prompt += f"<|user|> {message}\n<|assistant|>"
|
| 20 |
|
| 21 |
+
response = client.text_generation(
|
| 22 |
+
prompt,
|
| 23 |
+
max_new_tokens=512,
|
| 24 |
+
temperature=0.7,
|
| 25 |
+
top_p=0.95,
|
| 26 |
+
repetition_penalty=1.0,
|
| 27 |
+
do_sample=True
|
| 28 |
+
)
|
| 29 |
|
| 30 |
+
response = response.strip().split("<|assistant|>")[-1].strip()
|
| 31 |
history.append((message, response))
|
| 32 |
audio_path = speak_text(response)
|
| 33 |
return history, history, audio_path
|
|
|
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
gr.Markdown("# Sambit AI 🤖")
|
| 37 |
chatbot = gr.Chatbot([], label="Chat with AI", type="messages")
|
| 38 |
+
msg = gr.Textbox(label="Type your message here", placeholder="Ask me anything...", scale=7)
|
| 39 |
audio_output = gr.Audio(label="AI Voice", interactive=False)
|
| 40 |
|
| 41 |
+
clear = gr.Button("🧹 Clear Chat")
|
| 42 |
|
| 43 |
state = gr.State([])
|
| 44 |
|
| 45 |
msg.submit(respond, [msg, state], [chatbot, state, audio_output])
|
| 46 |
clear.click(lambda: ([], [], None), None, [chatbot, state, audio_output])
|
| 47 |
|
| 48 |
+
# ✅ Required to make it work on Hugging Face
|
| 49 |
demo.launch()
|
| 50 |
+
|