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