Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,29 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
inputs=gr.Textbox(lines=2, placeholder="Gali su'aal ku saabsan beeraha..."),
|
10 |
-
outputs="text",
|
11 |
-
title="Tacab Somali Agriculture Q&A",
|
12 |
-
description="Su'aalo iyo jawaabo ku saabsan waaxda beeraha ee Soomaaliya."
|
13 |
-
)
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
|
4 |
+
# Load the model from Hugging Face Hub
|
5 |
+
MODEL_NAME = "tacab/somali-agriculture"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
8 |
|
9 |
+
# Create text generation pipeline
|
10 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Function to use in the Gradio interface
|
13 |
+
def generate_text(prompt):
|
14 |
+
output = generator(
|
15 |
+
prompt,
|
16 |
+
do_sample=True,
|
17 |
+
max_length=200,
|
18 |
+
pad_token_id=tokenizer.eos_token_id
|
19 |
+
)
|
20 |
+
return output[0]["generated_text"]
|
21 |
+
|
22 |
+
# Build Gradio interface
|
23 |
+
gr.Interface(
|
24 |
+
fn=generate_text,
|
25 |
+
inputs=gr.Textbox(lines=3, label="Geli qoraalka/Prompt-ka"),
|
26 |
+
outputs=gr.Textbox(label="Natiijada/Generated Text"),
|
27 |
+
title="Tacab – Somali Agriculture Generator",
|
28 |
+
description="App-kan wuxuu adeegsadaa model-ka 'tacab/somali-agriculture' si uu u abuuro qoraal cusub oo la xiriira beeraha Soomaaliyeed."
|
29 |
+
).launch()
|