GeneXam / app.py
Rathapoom's picture
Update app.py
30cf447 verified
raw
history blame
1.13 kB
import streamlit as st
import openai
# Set your OpenAI API key using Streamlit secrets
openai.api_key = st.secrets["OPENAI_API_KEY"]
# Create an OpenAI client using the new API structure
client = openai.OpenAI(api_key=openai.api_key)
# Streamlit app
st.title("Exam Question Generator")
# Input field for user prompt
user_input = st.text_area("Enter knowledge material to generate exam questions:")
if st.button("Generate Questions"):
if user_input:
# Call OpenAI's Chat Completion API using the new structure
response = client.chat.completions.create(
model="gpt-4o-mini", # Or use "gpt-4" if available
messages=[
{"role": "system", "content": "You are a helpful assistant for generating exam questions."},
{"role": "user", "content": f"Generate exam questions from the following material: {user_input}"}
]
)
# Extract the response and display it
st.write("Generated Exam Questions:")
st.write(response.choices[0].message['content'])
else:
st.warning("Please enter the knowledge material.")