Spaces:
Sleeping
Sleeping
import streamlit as st | |
import openai | |
# Set your OpenAI API key using Streamlit secrets | |
openai.api_key = "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" | |
# 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-3.5-turbo", # 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 correctly | |
st.write("Generated Exam Questions:") | |
st.write(response.choices[0].message.content) # Access message content directly | |
else: | |
st.warning("Please enter the knowledge material.") | |