Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -164,4 +164,98 @@ st.markdown('''
|
|
164 |
Example above edited for readability.
|
165 |
AW - 05042024
|
166 |
|
167 |
-
''')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
Example above edited for readability.
|
165 |
AW - 05042024
|
166 |
|
167 |
+
''')
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
st.markdown('''
|
172 |
+
Observer analysis,
|
173 |
+
|
174 |
+
While ChatGPT did great at the first few asks, what it shared as portion of its output only solved half the problem.
|
175 |
+
NPS of observer - I would give it an 8. The specification is correct. Language to explain was excellent.
|
176 |
+
|
177 |
+
Accuracy=100% - all python libraries check out.
|
178 |
+
|
179 |
+
Coder Score = 0.
|
180 |
+
Specification Score = 50
|
181 |
+
Total out of 100 pts = 50 pts or 50% optimal in this battle.
|
182 |
+
|
183 |
+
''')
|
184 |
+
|
185 |
+
|
186 |
+
st.markdown(''' Claude goes next..''')
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
import streamlit as st
|
191 |
+
import fitz # PyMuPDF library for PDF files
|
192 |
+
import markdown # Markdown library for .md files
|
193 |
+
import pygments # Syntax highlighting library for source code files
|
194 |
+
import pygments.lexers as lexers
|
195 |
+
import pygments.formatters as formatters
|
196 |
+
import cairosvg # Library for converting SVG to PNG
|
197 |
+
import qoi # Library for QOI image format
|
198 |
+
|
199 |
+
# Function to read and display PDF files
|
200 |
+
def display_pdf(file):
|
201 |
+
doc = fitz.open(stream=file.read(), filetype="pdf")
|
202 |
+
for page in doc:
|
203 |
+
pix = page.get_pixmap()
|
204 |
+
img_bytes = pix.tobytes()
|
205 |
+
st.image(img_bytes, use_column_width=True)
|
206 |
+
|
207 |
+
# Function to read and display Markdown files
|
208 |
+
def display_markdown(file):
|
209 |
+
md_content = file.read().decode("utf-8")
|
210 |
+
html_content = markdown.markdown(md_content)
|
211 |
+
st.markdown(html_content, unsafe_allow_html=True)
|
212 |
+
|
213 |
+
# Function to read and display source code files with syntax highlighting
|
214 |
+
def display_source_code(file, file_extension):
|
215 |
+
code_content = file.read().decode("utf-8")
|
216 |
+
lexer = lexers.get_lexer_by_name(file_extension)
|
217 |
+
formatter = formatters.HtmlFormatter(style="colorful")
|
218 |
+
highlighted_code = pygments.highlight(code_content, lexer, formatter)
|
219 |
+
st.markdown(highlighted_code, unsafe_allow_html=True)
|
220 |
+
|
221 |
+
# Function to read and display SVG images
|
222 |
+
def display_svg(file):
|
223 |
+
svg_content = file.read().decode("utf-8")
|
224 |
+
png_content = cairosvg.svg2png(bytestring=svg_content)
|
225 |
+
st.image(png_content, use_column_width=True)
|
226 |
+
|
227 |
+
# Function to read and display G-code files
|
228 |
+
def display_gcode(file):
|
229 |
+
gcode_content = file.read().decode("utf-8")
|
230 |
+
st.code(gcode_content)
|
231 |
+
|
232 |
+
# Function to read and display QOI images
|
233 |
+
def display_qoi(file):
|
234 |
+
qoi_data = file.read()
|
235 |
+
image = qoi.decode(qoi_data)
|
236 |
+
st.image(image, use_column_width=True)
|
237 |
+
|
238 |
+
# Streamlit app
|
239 |
+
def main():
|
240 |
+
st.title("File Library Manager")
|
241 |
+
|
242 |
+
uploaded_file = st.file_uploader("Upload a file", type=["pdf", "md", "cs", "cpp", "rs", "svg", "gcode", "qoi"])
|
243 |
+
|
244 |
+
if uploaded_file is not None:
|
245 |
+
file_extension = uploaded_file.name.split(".")[-1].lower()
|
246 |
+
|
247 |
+
if file_extension == "pdf":
|
248 |
+
display_pdf(uploaded_file)
|
249 |
+
elif file_extension == "md":
|
250 |
+
display_markdown(uploaded_file)
|
251 |
+
elif file_extension in ["cs", "cpp", "rs"]:
|
252 |
+
display_source_code(uploaded_file, file_extension)
|
253 |
+
elif file_extension == "svg":
|
254 |
+
display_svg(uploaded_file)
|
255 |
+
elif file_extension == "gcode":
|
256 |
+
display_gcode(uploaded_file)
|
257 |
+
elif file_extension == "qoi":
|
258 |
+
display_qoi(uploaded_file)
|
259 |
+
else:
|
260 |
+
st.warning("Unsupported file type.")
|
261 |
+
main()
|