MainQuestion / app.py
mimoha's picture
Update app.py
fe221f0 verified
raw
history blame
1.23 kB
# app.py
from google import genai
import gradio as gr
API_KEY = "AIzaSyDedY-PdSeTyitSztgMl7c"
client = genai.Client(api_key=API_KEY)
MODEL_NAME = "gemini-1.5-flash"
def generate_main_question_gemini(paragraph: str):
if not paragraph or paragraph.strip() == "":
return "Please enter a paragraph first."
prompt = f"""
The following paragraph:
{paragraph}
Task:
- Generate one simple main question in Arabic (difficulty level: very easy).
"""
try:
response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
return response.text.strip()
except Exception as e:
return f"⚠️ Error while connecting to API: {e}"
with gr.Blocks() as demo:
gr.Markdown("## MainQuestion — Basic Question Generator (Arabic)")
with gr.Row():
paragraph = gr.Textbox(
label="Paragraph (Input text)",
lines=8,
placeholder="Paste the paragraph here..."
)
output = gr.Textbox(label="Generated Question", lines=3)
submit_btn = gr.Button("Submit")
submit_btn.click(fn=generate_main_question_gemini, inputs=paragraph, outputs=output)
if __name__ == "__main__":
demo.launch(share=True, show_error=True)