Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load models
|
5 |
+
gen_model = pipeline("text2text-generation", model="google/flan-t5-large")
|
6 |
+
translator_en_ar = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ar") # English to Arabic
|
7 |
+
translator_ar_en = pipeline("translation", model="Helsinki-NLP/opus-mt-ar-en") # Arabic to English
|
8 |
+
|
9 |
+
def get_plant_info(plant_name, language):
|
10 |
+
if language == "English":
|
11 |
+
prompt = (
|
12 |
+
f"Provide detailed information about {plant_name}. "
|
13 |
+
f"Include its scientific name, growing conditions (light, water, soil type), "
|
14 |
+
f"common uses, and how to take care of it."
|
15 |
+
)
|
16 |
+
response = gen_model(prompt, min_length=50, max_length=300)[0]["generated_text"]
|
17 |
+
else: # Arabic
|
18 |
+
translated_name = translator_ar_en(plant_name)[0]["translation_text"] # Convert Arabic input to English
|
19 |
+
prompt = (
|
20 |
+
f"Provide detailed information about {translated_name}. "
|
21 |
+
f"Include its scientific name, growing conditions (light, water, soil type), "
|
22 |
+
f"common uses, and how to take care of it."
|
23 |
+
)
|
24 |
+
response_en = gen_model(prompt, min_length=50, max_length=300)[0]["generated_text"]
|
25 |
+
response = translator_en_ar(response_en)[0]["translation_text"] # Convert English output back to Arabic
|
26 |
+
|
27 |
+
return response
|
28 |
+
|
29 |
+
# Gradio UI
|
30 |
+
interface = gr.Interface(
|
31 |
+
fn=get_plant_info,
|
32 |
+
inputs=[
|
33 |
+
gr.Textbox(label="Enter Plant Name / أدخل اسم النبات"),
|
34 |
+
gr.Radio(["English", "العربية"], label="Choose Language / اختر اللغة")
|
35 |
+
],
|
36 |
+
outputs=gr.Textbox(label="Plant Information / معلومات النبات", lines=10),
|
37 |
+
title="Plant Information App",
|
38 |
+
description="Enter a plant name and select a language to get detailed information."
|
39 |
+
)
|
40 |
+
|
41 |
+
# Launch the app
|
42 |
+
if __name__ == "__main__":
|
43 |
+
demo.launch()
|