Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,23 +2,27 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
#
|
| 6 |
chatbot = pipeline(
|
| 7 |
"text2text-generation",
|
| 8 |
-
model="
|
| 9 |
-
max_new_tokens=128
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
def chat_nepali(message, history):
|
|
|
|
| 13 |
history_text = ""
|
| 14 |
for user_msg, bot_msg in history:
|
| 15 |
history_text += f"User: {user_msg}\nBot: {bot_msg}\n"
|
| 16 |
prompt = f"{history_text}User: {message}\nBot:"
|
|
|
|
|
|
|
| 17 |
result = chatbot(prompt)[0]["generated_text"]
|
| 18 |
return result.strip()
|
| 19 |
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
-
gr.Markdown("## Nepali Chatbot 🇳🇵
|
| 22 |
chatbot_ui = gr.Chatbot()
|
| 23 |
msg = gr.Textbox(placeholder="नेपालीमा कुरा गर्नुहोस्...")
|
| 24 |
clear = gr.Button("Clear Chat")
|
|
@@ -27,4 +31,4 @@ with gr.Blocks() as demo:
|
|
| 27 |
clear.click(lambda: None, None, chatbot_ui, queue=False)
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|
| 30 |
-
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Load multilingual T5 (supports Nepali)
|
| 6 |
chatbot = pipeline(
|
| 7 |
"text2text-generation",
|
| 8 |
+
model="google/mt5-base",
|
| 9 |
+
max_new_tokens=128,
|
| 10 |
+
temperature=0.7
|
| 11 |
)
|
| 12 |
|
| 13 |
def chat_nepali(message, history):
|
| 14 |
+
# Concatenate history into a single prompt
|
| 15 |
history_text = ""
|
| 16 |
for user_msg, bot_msg in history:
|
| 17 |
history_text += f"User: {user_msg}\nBot: {bot_msg}\n"
|
| 18 |
prompt = f"{history_text}User: {message}\nBot:"
|
| 19 |
+
|
| 20 |
+
# Generate response
|
| 21 |
result = chatbot(prompt)[0]["generated_text"]
|
| 22 |
return result.strip()
|
| 23 |
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("## Nepali Chatbot 🇳🇵 using mT5")
|
| 26 |
chatbot_ui = gr.Chatbot()
|
| 27 |
msg = gr.Textbox(placeholder="नेपालीमा कुरा गर्नुहोस्...")
|
| 28 |
clear = gr.Button("Clear Chat")
|
|
|
|
| 31 |
clear.click(lambda: None, None, chatbot_ui, queue=False)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
+
demo.launch()
|