Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,54 +0,0 @@
|
|
1 |
-
|
2 |
-
import streamlit as st
|
3 |
-
from transformers import pipeline
|
4 |
-
from fpdf import FPDF
|
5 |
-
|
6 |
-
# Load lightweight model
|
7 |
-
@st.cache_resource
|
8 |
-
def load_model():
|
9 |
-
return pipeline("text2text-generation", model="google/flan-t5-small")
|
10 |
-
|
11 |
-
generator = load_model()
|
12 |
-
|
13 |
-
# Streamlit config
|
14 |
-
st.set_page_config(page_title="Explain Like I'm 5", page_icon="🧸", layout="centered")
|
15 |
-
st.markdown("<h1 style='text-align: center;'>🧸 Explain Like I'm 5</h1>", unsafe_allow_html=True)
|
16 |
-
st.markdown("<p style='text-align: center;'>Ask anything and I’ll explain it super simply 👶</p>", unsafe_allow_html=True)
|
17 |
-
|
18 |
-
# Input box
|
19 |
-
user_input = st.text_input("🎯 Enter a topic or question:", placeholder="e.g., What is blockchain?")
|
20 |
-
|
21 |
-
with st.expander("💡 Try These Examples"):
|
22 |
-
st.markdown("- What is AI?\n- Why is the sky blue?\n- How does Wi-Fi work?\n- What is climate change?")
|
23 |
-
|
24 |
-
# Explanation generation
|
25 |
-
def generate_eli5_response(topic):
|
26 |
-
prompt = f"Explain this like I’m 5: {topic}"
|
27 |
-
result = generator(prompt, max_new_tokens=100)
|
28 |
-
return result[0]['generated_text'].strip()
|
29 |
-
|
30 |
-
# PDF export function
|
31 |
-
def export_to_pdf(topic, explanation):
|
32 |
-
pdf = FPDF()
|
33 |
-
pdf.add_page()
|
34 |
-
pdf.set_font("Arial", size=12)
|
35 |
-
pdf.multi_cell(0, 10, f"Topic: {topic}\n\nExplanation:\n{explanation}")
|
36 |
-
return pdf.output(dest='S').encode('latin-1')
|
37 |
-
|
38 |
-
# Trigger logic
|
39 |
-
if st.button("✨ Explain it to me!"):
|
40 |
-
if user_input.strip() == "":
|
41 |
-
st.warning("Please enter a topic.")
|
42 |
-
else:
|
43 |
-
with st.spinner("Explaining like you're 5..."):
|
44 |
-
explanation = generate_eli5_response(user_input)
|
45 |
-
st.success("🍼 Here's your explanation:")
|
46 |
-
st.markdown(f"**{explanation}**")
|
47 |
-
|
48 |
-
# PDF Export
|
49 |
-
pdf_data = export_to_pdf(user_input, explanation)
|
50 |
-
st.download_button("📄 Download as PDF", data=pdf_data, file_name=f"ELI5-{user_input[:30]}.pdf", mime="application/pdf")
|
51 |
-
|
52 |
-
# Footer
|
53 |
-
st.markdown("---")
|
54 |
-
st.markdown("<p style='text-align: center;'>❤️ Made with Love. By Akash Shahade</p>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|