Spaces:
Sleeping
Sleeping
ishworrsubedii
commited on
Commit
•
94a57a0
1
Parent(s):
739ddb8
update: tempfile
Browse files
app.py
CHANGED
@@ -9,9 +9,8 @@ import zipfile
|
|
9 |
import io
|
10 |
import markdown2
|
11 |
import pdfkit
|
|
|
12 |
|
13 |
-
os.system("apt-get update")
|
14 |
-
os.system("apt-get install wkhtmltopdf")
|
15 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
16 |
llm_obj = LLMClient(client)
|
17 |
processor = CodeProcessor(llm_obj)
|
@@ -53,30 +52,35 @@ if code_dict:
|
|
53 |
|
54 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
html_output = markdown2.markdown(markdown_output)
|
64 |
-
|
65 |
-
|
|
|
66 |
|
67 |
with open(pdf_file_path, "rb") as pdf_file:
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
mime="application/pdf"
|
75 |
-
)
|
76 |
|
77 |
if st.sidebar.button("Batch Predict"):
|
78 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
79 |
all_markdowns = {}
|
|
|
80 |
for key, code_text in code_dict.items():
|
81 |
markdown_output = processor.process_code(code_text, model_choice)
|
82 |
all_markdowns[key] = markdown_output
|
@@ -84,26 +88,30 @@ if code_dict:
|
|
84 |
with st.expander(f"Analysis for {key}"):
|
85 |
st.markdown(markdown_output)
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
html_output = markdown2.markdown(markdown_output)
|
95 |
-
|
96 |
-
|
|
|
97 |
|
98 |
with open(pdf_file_path, "rb") as pdf_file:
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
mime="application/pdf"
|
106 |
-
)
|
107 |
|
108 |
zip_buffer = io.BytesIO()
|
109 |
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
|
|
|
9 |
import io
|
10 |
import markdown2
|
11 |
import pdfkit
|
12 |
+
import tempfile
|
13 |
|
|
|
|
|
14 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
15 |
llm_obj = LLMClient(client)
|
16 |
processor = CodeProcessor(llm_obj)
|
|
|
52 |
|
53 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
54 |
|
55 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".md") as tmp_md_file:
|
56 |
+
tmp_md_file.write(markdown_output.encode('utf-8'))
|
57 |
+
tmp_md_file_path = tmp_md_file.name
|
58 |
+
|
59 |
+
with open(tmp_md_file_path, "r") as md_file:
|
60 |
+
st.download_button(
|
61 |
+
label=f"Download {unique_key} Result as Markdown",
|
62 |
+
data=md_file,
|
63 |
+
file_name=f"code_analysis_{unique_key}_{timestamp}.md",
|
64 |
+
mime="text/markdown"
|
65 |
+
)
|
66 |
|
67 |
html_output = markdown2.markdown(markdown_output)
|
68 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf_file:
|
69 |
+
pdf_file_path = tmp_pdf_file.name
|
70 |
+
pdfkit.from_string(html_output, pdf_file_path)
|
71 |
|
72 |
with open(pdf_file_path, "rb") as pdf_file:
|
73 |
+
st.download_button(
|
74 |
+
label=f"Download {unique_key} Result as PDF",
|
75 |
+
data=pdf_file,
|
76 |
+
file_name=f"code_analysis_{unique_key}_{timestamp}.pdf",
|
77 |
+
mime="application/pdf"
|
78 |
+
)
|
|
|
|
|
79 |
|
80 |
if st.sidebar.button("Batch Predict"):
|
81 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
82 |
all_markdowns = {}
|
83 |
+
|
84 |
for key, code_text in code_dict.items():
|
85 |
markdown_output = processor.process_code(code_text, model_choice)
|
86 |
all_markdowns[key] = markdown_output
|
|
|
88 |
with st.expander(f"Analysis for {key}"):
|
89 |
st.markdown(markdown_output)
|
90 |
|
91 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".md") as tmp_md_file:
|
92 |
+
tmp_md_file.write(markdown_output.encode('utf-8'))
|
93 |
+
tmp_md_file_path = tmp_md_file.name
|
94 |
+
|
95 |
+
with open(tmp_md_file_path, "r") as md_file:
|
96 |
+
st.download_button(
|
97 |
+
label=f"Download {key} Result as Markdown",
|
98 |
+
data=md_file,
|
99 |
+
file_name=f"code_analysis_{key}_{timestamp}.md",
|
100 |
+
mime="text/markdown"
|
101 |
+
)
|
102 |
|
103 |
html_output = markdown2.markdown(markdown_output)
|
104 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf_file:
|
105 |
+
pdf_file_path = tmp_pdf_file.name
|
106 |
+
pdfkit.from_string(html_output, pdf_file_path)
|
107 |
|
108 |
with open(pdf_file_path, "rb") as pdf_file:
|
109 |
+
st.download_button(
|
110 |
+
label=f"Download {key} Result as PDF",
|
111 |
+
data=pdf_file,
|
112 |
+
file_name=f"code_analysis_{key}_{timestamp}.pdf",
|
113 |
+
mime="application/pdf"
|
114 |
+
)
|
|
|
|
|
115 |
|
116 |
zip_buffer = io.BytesIO()
|
117 |
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
|