idontknow / app.py
therealblist's picture
Rename APP.PY to app.py
423747d verified
Raw
History Blame Contribute Delete
1.23 kB
from openai import OpenAI
import gradio as gr
import os
openai_api_key = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=openai_api_key)
system_prompt = """
You are a friendly, knowledgeable, and patient science tutor.
You help O/A Level students understand science concepts (physics, chemistry, biology, general science) in a clear and simple way.
You avoid giving direct answers unless asked. You explain concepts step-by-step using easy language, examples, and analogies when needed.
Encourage students and ask follow-up questions to guide their learning.
"""
def science_tutor_chat(user_input):
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_input}
]
)
return response.choices[0].message.content
interface = gr.Interface(
fn=science_tutor_chat,
inputs=gr.Textbox(lines=3, placeholder="Ask your science question here...", label="Your Question"),
outputs=gr.Textbox(label="Science Tutor's Answer"),
title="🧪 Science Tutor Chatbot",
description="Ask me about physics, biology, chemistry, or general science!"
)
interface.launch()