Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the Hugging Face model
|
| 5 |
+
@st.cache_resource # Caches the model to improve loading time
|
| 6 |
+
def load_model():
|
| 7 |
+
return pipeline("text2text-generation", model="t5-base")
|
| 8 |
+
|
| 9 |
+
# Initialize the model
|
| 10 |
+
question_generator = load_model()
|
| 11 |
+
|
| 12 |
+
# Streamlit App Layout
|
| 13 |
+
st.title("AI-Powered Quiz Generator")
|
| 14 |
+
st.write("Create quizzes from any topic or text input using AI.")
|
| 15 |
+
|
| 16 |
+
# Input Section
|
| 17 |
+
st.subheader("Input Text or Topic")
|
| 18 |
+
input_text = st.text_area("Enter your text or topic here:", height=200)
|
| 19 |
+
|
| 20 |
+
# Button to generate questions
|
| 21 |
+
if st.button("Generate Quiz"):
|
| 22 |
+
if input_text.strip():
|
| 23 |
+
st.subheader("Generated Questions")
|
| 24 |
+
with st.spinner("Generating questions..."):
|
| 25 |
+
# Generate questions
|
| 26 |
+
questions = question_generator(input_text, max_length=50, num_return_sequences=5)
|
| 27 |
+
for i, question in enumerate(questions):
|
| 28 |
+
st.write(f"{i+1}. {question['generated_text']}")
|
| 29 |
+
else:
|
| 30 |
+
st.error("Please enter some text or topic to generate the quiz!")
|
| 31 |
+
|
| 32 |
+
# Footer
|
| 33 |
+
st.markdown("---")
|
| 34 |
+
st.markdown("**Created by [Your Name]** | Powered by Hugging Face & Streamlit")
|