aakashdevdat commited on
Commit
6ef5f0e
·
verified ·
1 Parent(s): 1234809

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Title
5
+ st.title("📘 Quiz Generator from Text")
6
+ st.write("Enter a paragraph, and this app will generate MCQs using a Hugging Face model.")
7
+
8
+ # Load model only once
9
+ @st.cache_resource
10
+ def load_model():
11
+ return pipeline("e2e-qg", model="valhalla/t5-base-e2e-qg")
12
+
13
+ qg_pipeline = load_model()
14
+
15
+ # Text input
16
+ text = st.text_area("Enter your paragraph here:", height=200)
17
+
18
+ if st.button("Generate Quiz"):
19
+ if not text.strip():
20
+ st.warning("Please enter some text first.")
21
+ else:
22
+ with st.spinner("Generating questions..."):
23
+ try:
24
+ result = qg_pipeline(text)
25
+ st.success("Here are your questions:")
26
+
27
+ for idx, item in enumerate(result):
28
+ st.markdown(f"**Q{idx+1}. {item['question']}**")
29
+ st.markdown(f"- Answer: `{item['answer']}`")
30
+ st.markdown("---")
31
+ except Exception as e:
32
+ st.error(f"Error: {str(e)}")