Spaces:
Runtime error
Runtime error
File size: 1,297 Bytes
cdbaf8e 71e68f6 cdbaf8e 71e68f6 cdbaf8e 71e68f6 cdbaf8e 71e68f6 cdbaf8e 71e68f6 cdbaf8e 71e68f6 cdbaf8e 71e68f6 | 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 | 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() |