AamerAkhter commited on
Commit
518c0a4
·
verified ·
1 Parent(s): d548b46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -24
app.py CHANGED
@@ -1,29 +1,22 @@
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)")
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ # Load question generation pipeline
5
+ qg_pipeline = pipeline("text2text-generation", model="iarfmoose/t5-base-question-generator")
6
 
7
+ st.title("AI-Powered Quiz Generator")
8
+ text = st.text_area("Enter a topic or paragraph to generate quiz questions:")
9
 
10
+ if st.button("Generate Quiz"):
11
+ with st.spinner("Generating questions..."):
12
+ output = qg_pipeline(f"generate questions: {text}", max_length=512, do_sample=True, temperature=0.7)
13
+ questions = output[0]['generated_text'].split('\n')
14
+
15
+ score = 0
16
+ for i, question in enumerate(questions):
17
+ if question.strip():
18
+ st.write(f"**Q{i+1}: {question}**")
19
+ answer = st.radio("Your Answer:", ['Option A', 'Option B', 'Option C', 'Option D'], key=i)
20
+ # You can set correct answers with additional logic
21
 
22
+ st.success("Quiz complete! (Scoring can be added based on correct options)")