Spaces:
Running
Running
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134import gradio as grfrom openai import OpenAIimport osclient = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))SYSTEM_PROMPT = """You are StudyAI, a friendly tutor for secondary school students.Rules:- Explain things clearly and step by step- Help the student understand instead of only giving answers- Give examples when useful- For maths, show working- Keep explanations clear and not unnecessarily long- For quizzes, do not reveal answers immediately- If unsure about something, say so instead of inventing information"""def study_ai(message, history, subject, mode):if not message.strip():return "Type something first!"instructions = {"Ask anything":f"Answer the student's question about {subject}.","Explain":f"""Explain this {subject} topic:{message}Include:1. Simple explanation2. Important points3. An example4. Short recap""","Quiz me":f"""Create a 5-question quiz about this {subject} topic:{message}Do not give the answers yet.""","Flashcards":f"""Create 10 flashcards about this {subject} topic:{message}Format each as:Q: ...A: ...""","Study plan":f"""Create a realistic study plan based on:{message}Include revision, practice questions, active recall and breaks.""","Check my answer":f"""Check the student's {subject} answer:{message}Explain:1. What is correct2. What needs improvement3. A better answer or method4. One revision tip"""}prompt = instructions.get(mode, message)if mode == "Ask anything":prompt += f"\n\nStudent question:\n{message}"response = client.responses.create(model="gpt-5.4-mini",instructions=SYSTEM_PROMPT,input=prompt)return response.output_textwith gr.Blocks(title="FYR StudyAI") as demo:gr.Markdown("""# ๐ FYR StudyAI### Your AI study assistantAsk questions, revise topics, generate quizzes and make flashcards.""")with gr.Row():subject = gr.Dropdown(["General","Mathematics","Science","English","Chinese","History","Geography"],value="General",label="๐ Subject")mode = gr.Dropdown(["Ask anything","Explain","Quiz me","Flashcards","Study plan","Check my answer"],value="Ask anything",label="๐ ๏ธ Study Tool")chatbot = gr.ChatInterface(fn=study_ai,additional_inputs=[subject, mode],textbox=gr.Textbox(placeholder="Ask StudyAI something...",lines=2))gr.Markdown("โ ๏ธ StudyAI can make mistakes. Check important information with your notes or teacher.")demo.launch()
app.py+134