akashshahade commited on
Commit
e91c8fa
·
verified ·
1 Parent(s): fe9f4ae

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+ from fpdf import FPDF
5
+
6
+ # Load model using a public one
7
+ @st.cache_resource
8
+ def load_model():
9
+ return pipeline("text-generation", model="tiiuae/falcon-7b-instruct")
10
+
11
+ generator = load_model()
12
+
13
+ # Page 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
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
+ # Generate explanation
25
+ def generate_eli5_response(topic):
26
+ prompt = f"Explain this to a 5-year-old: {topic}"
27
+ result = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
28
+ return result[0]['generated_text'].replace(prompt, "").strip()
29
+
30
+ # PDF Export
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
+ # Run
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
+ # Export to PDF
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)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+ streamlit
3
+ transformers
4
+ torch
5
+ fpdf