Spaces:
Runtime error
Runtime error
Update sketch2diagram.py
Browse files- sketch2diagram.py +23 -24
sketch2diagram.py
CHANGED
|
@@ -47,7 +47,6 @@ if input_file is not None:
|
|
| 47 |
st.image(input_file, caption="Uploaded Sketch")
|
| 48 |
generate_command = st.button("Generate TikZ Code")
|
| 49 |
|
| 50 |
-
# Run model inference
|
| 51 |
if generate_command:
|
| 52 |
with st.spinner("Generating TikZ code..."):
|
| 53 |
try:
|
|
@@ -55,30 +54,30 @@ if generate_command:
|
|
| 55 |
except Exception as e:
|
| 56 |
st.error(f"Inference failed: {e}")
|
| 57 |
st.session_state.clear()
|
| 58 |
-
return
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
st.download_button(
|
| 66 |
-
label="Download LaTeX Code",
|
| 67 |
-
data=output,
|
| 68 |
-
file_name="output.tex",
|
| 69 |
-
mime="text/plain"
|
| 70 |
-
)
|
| 71 |
|
| 72 |
-
st.subheader("Generated Diagram")
|
| 73 |
-
images = convert_from_path(pdf_file_path)
|
| 74 |
-
st.image(images[0], caption="Generated Diagram", use_container_width=True)
|
| 75 |
-
with open(pdf_file_path, "rb") as f:
|
| 76 |
st.download_button(
|
| 77 |
-
label="Download
|
| 78 |
-
data=
|
| 79 |
-
file_name="output.
|
| 80 |
-
mime="
|
| 81 |
)
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
st.image(input_file, caption="Uploaded Sketch")
|
| 48 |
generate_command = st.button("Generate TikZ Code")
|
| 49 |
|
|
|
|
| 50 |
if generate_command:
|
| 51 |
with st.spinner("Generating TikZ code..."):
|
| 52 |
try:
|
|
|
|
| 54 |
except Exception as e:
|
| 55 |
st.error(f"Inference failed: {e}")
|
| 56 |
st.session_state.clear()
|
| 57 |
+
# return # <-- REMOVE THIS LINE!
|
| 58 |
+
else:
|
| 59 |
+
pdf_file_path = compile_tikz_to_pdf(output)
|
| 60 |
+
if output and pdf_file_path:
|
| 61 |
+
st.subheader("Generated TikZ Code")
|
| 62 |
+
st.success("TikZ code generated successfully!")
|
| 63 |
+
st.code(output, language='latex')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
st.download_button(
|
| 66 |
+
label="Download LaTeX Code",
|
| 67 |
+
data=output,
|
| 68 |
+
file_name="output.tex",
|
| 69 |
+
mime="text/plain"
|
| 70 |
)
|
| 71 |
|
| 72 |
+
st.subheader("Generated Diagram")
|
| 73 |
+
images = convert_from_path(pdf_file_path)
|
| 74 |
+
st.image(images[0], caption="Generated Diagram", use_container_width=True)
|
| 75 |
+
|
| 76 |
+
with open(pdf_file_path, "rb") as f:
|
| 77 |
+
st.download_button(
|
| 78 |
+
label="Download PDF",
|
| 79 |
+
data=f.read(),
|
| 80 |
+
file_name="output.pdf",
|
| 81 |
+
mime="application/pdf"
|
| 82 |
+
)
|
| 83 |
+
|