zakihassan04 commited on
Commit
e56d38e
·
verified ·
1 Parent(s): 57e6531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -4
app.py CHANGED
@@ -1,8 +1,44 @@
1
  import gradio as gr
 
 
 
 
 
 
2
 
3
- def greet(msg):
4
- return "Haye! Waxaad tidhi: " + msg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  if __name__ == "__main__":
8
- iface.launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import (
4
+ MT5ForConditionalGeneration,
5
+ MT5TokenizerFast,
6
+ pipeline,
7
+ )
8
 
9
+ MODEL_ID = "tacab/mt5-beero_somali"
10
+
11
+ # Load tokenizer & model
12
+ tokenizer = MT5TokenizerFast.from_pretrained(MODEL_ID)
13
+ model = MT5ForConditionalGeneration.from_pretrained(MODEL_ID)
14
+ device = 0 if torch.cuda.is_available() else -1
15
+
16
+ # Build pipeline
17
+ qa = pipeline(
18
+ "text2text-generation",
19
+ model=model,
20
+ tokenizer=tokenizer,
21
+ device=device,
22
+ max_new_tokens=200,
23
+ min_length=100,
24
+ num_beams=4,
25
+ length_penalty=0.7,
26
+ no_repeat_ngram_size=3,
27
+ early_stopping=False,
28
+ )
29
+
30
+ def answer(question: str) -> str:
31
+ prompt = f"Su'aal: {question}"
32
+ out = qa(prompt)
33
+ return out[0]["generated_text"]
34
+
35
+ demo = gr.Interface(
36
+ fn=answer,
37
+ inputs=gr.Textbox(lines=2, placeholder="Gali su'aashaada...", label="Su'aal"),
38
+ outputs=gr.Textbox(label="Jawaab"),
39
+ title="Beero Somali Q&A",
40
+ description="Su'aal–Jawaab module ku saleysan tacab/mt5-beero_somali",
41
+ )
42
 
 
43
  if __name__ == "__main__":
44
+ demo.launch()