Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import openai
|
3 |
+
|
4 |
+
# Set your OpenAI API key
|
5 |
+
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
6 |
+
|
7 |
+
# Streamlit app
|
8 |
+
st.title("Test OpenAI API in Streamlit")
|
9 |
+
|
10 |
+
# User input
|
11 |
+
user_input = st.text_area("Enter prompt to generate questions:")
|
12 |
+
|
13 |
+
if st.button("Generate Questions"):
|
14 |
+
if user_input:
|
15 |
+
# Call OpenAI API
|
16 |
+
response = openai.Completion.create(
|
17 |
+
model="gpt-4o-mini",
|
18 |
+
prompt=f"Generate exam questions from the following material: {user_input}",
|
19 |
+
max_tokens=1000,
|
20 |
+
temperature=0.7,
|
21 |
+
)
|
22 |
+
# Display the generated questions
|
23 |
+
st.write("Generated Questions:")
|
24 |
+
st.write(response.choices[0].text)
|
25 |
+
else:
|
26 |
+
st.warning("Please enter a prompt.")
|