import gradio as gr import os from openai import OpenAI # Initialize OpenAI client client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) def study_ai(question, language="English"): """StudyMyExam AI: gives answers, quizzes, flashcards, and a tip.""" prompt = f""" You are StudyMyExam AI, a helpful learning assistant. Respond in {language}. 1. Give a clear answer to the question. 2. Create 5 quiz questions about the topic. 3. Make 5 flashcards with key points. 4. End with one motivational tip for studying. Question: {question} """ try: response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}], temperature=0.7, ) return response.choices[0].message.content except Exception as e: return f"❌ Error: {str(e)}" # Create Gradio interface interface = gr.Interface( fn=study_ai, inputs=[ gr.Textbox(label="Ask your question"), gr.Textbox(label="Language (e.g., English, Spanish)", value="English"), ], outputs=gr.Textbox(label="AI Response"), title="📘 StudyMyExam.AI", description="Ask any study question. Get explanations, quizzes, flashcards, and tips!" ) interface.launch()