Spaces:
Sleeping
Sleeping
File size: 929 Bytes
213f539 5946090 213f539 5946090 213f539 |
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 |
import streamlit as st
import openai
# Set your OpenAI API key
openai.api_key = st.secrets["OPENAI_API_KEY"]
# Streamlit app
st.title("Test OpenAI API in Streamlit")
# User input
user_input = st.text_area("Enter prompt to generate questions:")
if st.button("Generate Questions"):
if user_input:
# Use the new chat-based API
response = openai.ChatCompletion.create(
model="gpt-4o-mini", # You can use "gpt-4" if available
messages=[
{"role": "system", "content": "You are a helpful assistant that generates exam questions."},
{"role": "user", "content": f"Generate exam questions from the following material: {user_input}"}
]
)
# Display the generated questions
st.write("Generated Questions:")
st.write(response['choices'][0]['message']['content'])
else:
st.warning("Please enter a prompt.")
|