GeneXam / app.py
Rathapoom's picture
Create app.py
213f539 verified
raw
history blame
745 Bytes
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:
# Call OpenAI API
response = openai.Completion.create(
model="gpt-4o-mini",
prompt=f"Generate exam questions from the following material: {user_input}",
max_tokens=1000,
temperature=0.7,
)
# Display the generated questions
st.write("Generated Questions:")
st.write(response.choices[0].text)
else:
st.warning("Please enter a prompt.")