Spaces:
Build error
Build error
Commit
·
1f431b3
1
Parent(s):
76115d7
add: mdfile to pdf
Browse files- app.py +31 -0
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -7,6 +7,8 @@ from logic import LLMClient, CodeProcessor
|
|
| 7 |
from batch_code_logic_csv import csv_read_batch_code
|
| 8 |
import zipfile
|
| 9 |
import io
|
|
|
|
|
|
|
| 10 |
|
| 11 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 12 |
llm_obj = LLMClient(client)
|
|
@@ -48,6 +50,7 @@ if code_dict:
|
|
| 48 |
st.markdown(markdown_output)
|
| 49 |
|
| 50 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
| 51 |
st.download_button(
|
| 52 |
label=f"Download {unique_key} Result as Markdown",
|
| 53 |
data=markdown_output,
|
|
@@ -55,6 +58,20 @@ if code_dict:
|
|
| 55 |
mime="text/markdown"
|
| 56 |
)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
if st.sidebar.button("Batch Predict"):
|
| 59 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 60 |
all_markdowns = {}
|
|
@@ -72,6 +89,20 @@ if code_dict:
|
|
| 72 |
mime="text/markdown"
|
| 73 |
)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
zip_buffer = io.BytesIO()
|
| 76 |
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
|
| 77 |
for key, markdown_output in all_markdowns.items():
|
|
|
|
| 7 |
from batch_code_logic_csv import csv_read_batch_code
|
| 8 |
import zipfile
|
| 9 |
import io
|
| 10 |
+
import markdown2
|
| 11 |
+
import pdfkit
|
| 12 |
|
| 13 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 14 |
llm_obj = LLMClient(client)
|
|
|
|
| 50 |
st.markdown(markdown_output)
|
| 51 |
|
| 52 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 53 |
+
|
| 54 |
st.download_button(
|
| 55 |
label=f"Download {unique_key} Result as Markdown",
|
| 56 |
data=markdown_output,
|
|
|
|
| 58 |
mime="text/markdown"
|
| 59 |
)
|
| 60 |
|
| 61 |
+
html_output = markdown2.markdown(markdown_output)
|
| 62 |
+
pdf_file_path = f"code_analysis_{unique_key}_{timestamp}.pdf"
|
| 63 |
+
pdfkit.from_string(html_output, pdf_file_path)
|
| 64 |
+
|
| 65 |
+
with open(pdf_file_path, "rb") as pdf_file:
|
| 66 |
+
pdf_data = pdf_file.read()
|
| 67 |
+
|
| 68 |
+
st.download_button(
|
| 69 |
+
label=f"Download {unique_key} Result as PDF",
|
| 70 |
+
data=pdf_data,
|
| 71 |
+
file_name=pdf_file_path,
|
| 72 |
+
mime="application/pdf"
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
if st.sidebar.button("Batch Predict"):
|
| 76 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 77 |
all_markdowns = {}
|
|
|
|
| 89 |
mime="text/markdown"
|
| 90 |
)
|
| 91 |
|
| 92 |
+
html_output = markdown2.markdown(markdown_output)
|
| 93 |
+
pdf_file_path = f"code_analysis_{key}_{timestamp}.pdf"
|
| 94 |
+
pdfkit.from_string(html_output, pdf_file_path)
|
| 95 |
+
|
| 96 |
+
with open(pdf_file_path, "rb") as pdf_file:
|
| 97 |
+
pdf_data = pdf_file.read()
|
| 98 |
+
|
| 99 |
+
st.download_button(
|
| 100 |
+
label=f"Download {key} Result as PDF",
|
| 101 |
+
data=pdf_data,
|
| 102 |
+
file_name=pdf_file_path,
|
| 103 |
+
mime="application/pdf"
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
zip_buffer = io.BytesIO()
|
| 107 |
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
|
| 108 |
for key, markdown_output in all_markdowns.items():
|
requirements.txt
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
groq
|
| 2 |
streamlit
|
| 3 |
pandas
|
| 4 |
-
numpy
|
|
|
|
|
|
|
|
|
| 1 |
groq
|
| 2 |
streamlit
|
| 3 |
pandas
|
| 4 |
+
numpy
|
| 5 |
+
pdfkit
|
| 6 |
+
markdown2
|