Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,134 +1,122 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
from
|
4 |
-
import numpy as np
|
5 |
-
from imutils.video import VideoStream
|
6 |
import pikepdf
|
7 |
-
import fpdf
|
8 |
import fitz # pymupdf
|
9 |
-
import vidgear.gears
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
def
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
return "demo_opencv.jpg"
|
44 |
-
cap.release()
|
45 |
-
return None
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
frame = vs.read()
|
50 |
-
vs.stop()
|
51 |
-
if frame is not None:
|
52 |
-
cv2.imwrite("demo_imutils.jpg", cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
|
53 |
-
return "demo_imutils.jpg"
|
54 |
-
return None
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
frame = stream.read()
|
59 |
-
stream.stop()
|
60 |
-
if frame is not None:
|
61 |
-
cv2.imwrite("demo_vidgear.jpg", frame)
|
62 |
-
return "demo_vidgear.jpg"
|
63 |
-
return None
|
64 |
|
65 |
-
|
66 |
-
st.
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
st.
|
72 |
-
|
73 |
-
if st.button("
|
74 |
-
with st.spinner("
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
-
#
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
st.error("Camera not detected!")
|
101 |
-
elif demo == "imutils":
|
102 |
-
result = demo_imutils()
|
103 |
-
if result:
|
104 |
-
st.image(result, caption="Snapped with Imutils!")
|
105 |
-
else:
|
106 |
-
st.error("Camera not detected!")
|
107 |
-
except Exception as e:
|
108 |
-
st.error(f"Demo failed: {str(e)}")
|
109 |
-
|
110 |
-
# 🎥 Video Capture Demos
|
111 |
-
elif demo_type == "Video Capture":
|
112 |
-
st.subheader("🎥 Video Vanguards")
|
113 |
-
demo = st.selectbox("Pick a Video Demo", ["opencv-python", "vidgear"])
|
114 |
-
if st.button("Run Video Demo"):
|
115 |
-
with st.spinner("Capturing video frame..."):
|
116 |
-
try:
|
117 |
-
if demo == "opencv-python":
|
118 |
-
result = demo_opencv_image() # Using image capture as a proxy
|
119 |
-
if result:
|
120 |
-
st.image(result, caption="Frame from OpenCV Video!")
|
121 |
-
else:
|
122 |
-
st.error("Camera not detected!")
|
123 |
-
elif demo == "vidgear":
|
124 |
-
result = demo_vidgear()
|
125 |
-
if result:
|
126 |
-
st.image(result, caption="Frame from VidGear Video!")
|
127 |
-
else:
|
128 |
-
st.error("Camera not detected!")
|
129 |
-
except Exception as e:
|
130 |
-
st.error(f"Demo failed: {str(e)}")
|
131 |
-
|
132 |
-
# 📊 Results Display
|
133 |
-
st.write("### Results")
|
134 |
-
st.write("Check out your impressive outputs above!")
|
|
|
1 |
import streamlit as st
|
2 |
+
import base64
|
3 |
+
from fpdf import FPDF
|
|
|
|
|
4 |
import pikepdf
|
|
|
5 |
import fitz # pymupdf
|
|
|
6 |
|
7 |
+
# Define the 12-point ML outline with emojis
|
8 |
+
ml_outline = [
|
9 |
+
"🌟 1. Mixture of Experts (MoE)",
|
10 |
+
"🔥 2. Supervised Fine-Tuning (SFT) using PyTorch",
|
11 |
+
"🤖 3. Large Language Models (LLM) using Transformers",
|
12 |
+
"📊 4. Self-Rewarding Learning using NPS 0-10 and Verbatims",
|
13 |
+
"👍 5. Reinforcement Learning from Human Feedback (RLHF)",
|
14 |
+
"🔗 6. MergeKit: Merging Models to Same Embedding Space",
|
15 |
+
"📏 7. DistillKit: Model Size Reduction with Spectrum Analysis",
|
16 |
+
"🧠 8. Agentic RAG Agents using Document Inputs",
|
17 |
+
"⏳ 9. Longitudinal Data Summarization from Multiple Docs",
|
18 |
+
"📑 10. Knowledge Extraction using Markdown Knowledge Graphs",
|
19 |
+
"🗺️ 11. Knowledge Mapping with Mermaid Diagrams",
|
20 |
+
"💻 12. ML Code Generation with Streamlit/Gradio/HTML5+JS"
|
21 |
+
]
|
22 |
|
23 |
+
def create_pdf_with_library(library_name, outline_items):
|
24 |
+
if library_name == "fpdf":
|
25 |
+
pdf = FPDF(orientation='L', unit='mm', format='A4')
|
26 |
+
pdf.add_page()
|
27 |
+
pdf.set_font("Arial", size=10)
|
28 |
+
|
29 |
+
# Left page (1-6)
|
30 |
+
pdf.set_xy(10, 10)
|
31 |
+
pdf.multi_cell(140, 5, "Cutting-Edge ML Areas (1-6)\n\n" + "\n".join(outline_items[:6]))
|
32 |
+
|
33 |
+
# Right page (7-12)
|
34 |
+
pdf.set_xy(150, 10)
|
35 |
+
pdf.multi_cell(140, 5, "Cutting-Edge ML Areas (7-12)\n\n" + "\n".join(outline_items[6:]))
|
36 |
+
|
37 |
+
filename = "ml_outline_fpdf.pdf"
|
38 |
+
pdf.output(filename)
|
39 |
+
return filename
|
40 |
|
41 |
+
elif library_name == "pikepdf":
|
42 |
+
pdf = pikepdf.Pdf.new()
|
43 |
+
page = pikepdf.Page(pdf.make_stream(b""))
|
44 |
+
# Simplified content for pikepdf
|
45 |
+
pdf.pages.append(page)
|
46 |
+
filename = "ml_outline_pikepdf.pdf"
|
47 |
+
pdf.save(filename)
|
48 |
+
return filename
|
49 |
|
50 |
+
elif library_name == "pymupdf":
|
51 |
+
doc = fitz.open()
|
52 |
+
page = doc.new_page(width=842, height=595) # A4 landscape
|
53 |
+
# Left column
|
54 |
+
page.insert_text((20, 20), "Cutting-Edge ML Areas (1-6)\n\n" + "\n".join(outline_items[:6]),
|
55 |
+
fontsize=10)
|
56 |
+
# Right column
|
57 |
+
page.insert_text((422, 20), "Cutting-Edge ML Areas (7-12)\n\n" + "\n".join(outline_items[6:]),
|
58 |
+
fontsize=10)
|
59 |
+
filename = "ml_outline_pymupdf.pdf"
|
60 |
+
doc.save(filename)
|
61 |
+
return filename
|
62 |
|
63 |
+
def get_binary_file_downloader_html(bin_file, file_label='File'):
|
64 |
+
with open(bin_file, 'rb') as f:
|
65 |
+
data = f.read()
|
66 |
+
bin_str = base64.b64encode(data).decode()
|
67 |
+
href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{file_label}">Download {file_label}</a>'
|
68 |
+
return href
|
|
|
|
|
|
|
69 |
|
70 |
+
# Streamlit UI
|
71 |
+
st.title("🚀 Cutting-Edge ML Outline Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
# Two-column layout
|
74 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
with col1:
|
77 |
+
st.header("📝 Markdown Outline")
|
78 |
+
outline_text = "\n".join(ml_outline)
|
79 |
+
st.markdown(outline_text)
|
80 |
+
|
81 |
+
# Download markdown file
|
82 |
+
md_file = "ml_outline.md"
|
83 |
+
with open(md_file, "w") as f:
|
84 |
+
f.write(outline_text)
|
85 |
+
st.markdown(get_binary_file_downloader_html(md_file, "ml_outline.md"), unsafe_allow_html=True)
|
86 |
|
87 |
+
with col2:
|
88 |
+
st.header("📑 PDF Preview")
|
89 |
+
pdf_library = st.selectbox("Choose PDF Library", ["fpdf", "pikepdf", "pymupdf"])
|
90 |
+
|
91 |
+
if st.button("Generate PDF"):
|
92 |
+
with st.spinner("Generating PDF..."):
|
93 |
+
pdf_file = create_pdf_with_library(pdf_library, ml_outline)
|
94 |
+
|
95 |
+
# Auto-save and display PDF
|
96 |
+
with open(pdf_file, "rb") as f:
|
97 |
+
pdf_bytes = f.read()
|
98 |
+
|
99 |
+
st.download_button(
|
100 |
+
label="Download PDF",
|
101 |
+
data=pdf_bytes,
|
102 |
+
file_name=pdf_file,
|
103 |
+
mime="application/pdf"
|
104 |
+
)
|
105 |
+
|
106 |
+
# Display PDF
|
107 |
+
base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8')
|
108 |
+
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="100%" height="400" type="application/pdf"></iframe>'
|
109 |
+
st.markdown(pdf_display, unsafe_allow_html=True)
|
110 |
|
111 |
+
# Add some style
|
112 |
+
st.markdown("""
|
113 |
+
<style>
|
114 |
+
.stButton>button {
|
115 |
+
background-color: #4CAF50;
|
116 |
+
color: white;
|
117 |
+
}
|
118 |
+
.stSelectbox {
|
119 |
+
max-width: 300px;
|
120 |
+
}
|
121 |
+
</style>
|
122 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|