Spaces:
Sleeping
Sleeping
File size: 1,313 Bytes
213f539 30cf447 854f88d 213f539 30cf447 213f539 30cf447 213f539 30cf447 213f539 30cf447 213f539 30cf447 511dc51 5946090 30cf447 5946090 213f539 30cf447 511dc51 30cf447 511dc51 213f539 30cf447 511dc51 |
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 |
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.")
|