Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,31 @@
|
|
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("
|
9 |
|
10 |
-
#
|
11 |
-
user_input = st.text_area("Enter
|
12 |
|
13 |
-
if st.button("Generate
|
14 |
if user_input:
|
15 |
-
#
|
16 |
-
|
17 |
-
model="gpt-4o-mini", # Or use "gpt-4" if available
|
18 |
messages=[
|
19 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
20 |
-
{"role": "user", "content": user_input}
|
21 |
]
|
22 |
)
|
23 |
-
|
24 |
-
|
25 |
-
st.write(
|
|
|
26 |
else:
|
27 |
-
st.warning("Please enter
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
|
4 |
+
# Set your OpenAI API key using Streamlit secrets
|
5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
6 |
|
7 |
+
# Create an OpenAI client using the new API structure
|
8 |
+
client = openai.OpenAI(api_key=openai.api_key)
|
9 |
+
|
10 |
# Streamlit app
|
11 |
+
st.title("Exam Question Generator")
|
12 |
|
13 |
+
# Input field for user prompt
|
14 |
+
user_input = st.text_area("Enter knowledge material to generate exam questions:")
|
15 |
|
16 |
+
if st.button("Generate Questions"):
|
17 |
if user_input:
|
18 |
+
# Call OpenAI's Chat Completion API using the new structure
|
19 |
+
response = client.chat.completions.create(
|
20 |
+
model="gpt-4o-mini", # Or use "gpt-4" if available
|
21 |
messages=[
|
22 |
+
{"role": "system", "content": "You are a helpful assistant for generating exam questions."},
|
23 |
+
{"role": "user", "content": f"Generate exam questions from the following material: {user_input}"}
|
24 |
]
|
25 |
)
|
26 |
+
|
27 |
+
# Extract the response and display it
|
28 |
+
st.write("Generated Exam Questions:")
|
29 |
+
st.write(response.choices[0].message['content'])
|
30 |
else:
|
31 |
+
st.warning("Please enter the knowledge material.")
|