Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load Somali model
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("cmlang/somali-flan-t5")
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("cmlang/somali-flan-t5")
|
8 |
+
|
9 |
+
# Chatbot function
|
10 |
+
def chatbot_somali(msg):
|
11 |
+
inputs = tokenizer(msg, return_tensors="pt")
|
12 |
+
outputs = model.generate(**inputs, max_length=150)
|
13 |
+
reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
return reply
|
15 |
+
|
16 |
+
# Gradio Interface
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=chatbot_somali,
|
19 |
+
inputs=gr.Textbox(lines=2, placeholder="Weydii wax af Soomaali ah..."),
|
20 |
+
outputs="text",
|
21 |
+
title="Chatbot Af Soomaali",
|
22 |
+
description="Weydii wax kasta oo af Soomaali ah — chatbot-kan wuu fahmi doonaa!"
|
23 |
+
)
|
24 |
+
|
25 |
+
iface.launch()
|