Spaces:
Running
Running
File size: 1,130 Bytes
213f539 30cf447 213f539 30cf447 213f539 30cf447 213f539 30cf447 213f539 30cf447 213f539 30cf447 5946090 30cf447 5946090 213f539 30cf447 213f539 30cf447 |
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 |
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.")
|