Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
st.title("AI-Powered Quiz App")
|
5 |
+
st.write("Answer questions generated by AI based on your selected topic!")
|
6 |
+
|
7 |
+
# Select topic
|
8 |
+
topic = st.text_input("Enter a quiz topic (e.g., Python, Space, History):")
|
9 |
+
|
10 |
+
# Hugging Face model API (example: T5)
|
11 |
+
API_URL = "https://api-inference.huggingface.co/models/tuner007/t5_question_generator"
|
12 |
+
headers = {"Authorization": f"Bearer YOUR_HF_API_KEY"}
|
13 |
+
|
14 |
+
def query(prompt):
|
15 |
+
payload = {"inputs": prompt}
|
16 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
+
return response.json()
|
18 |
+
|
19 |
+
if st.button("Generate Question"):
|
20 |
+
if topic:
|
21 |
+
prompt = f"generate question: {topic}"
|
22 |
+
output = query(prompt)
|
23 |
+
question = output[0]['generated_text']
|
24 |
+
st.session_state['question'] = question
|
25 |
+
st.write(f"**Question:** {question}")
|
26 |
+
st.text_input("Your Answer", key="answer")
|
27 |
+
|
28 |
+
if 'question' in st.session_state and st.button("Check Answer"):
|
29 |
+
st.write("Answer checking is coming soon... (can integrate GPT here for answer matching)")
|