aika42 commited on
Commit
12e7fdd
·
verified ·
1 Parent(s): 458f0ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -3,7 +3,8 @@ import streamlit as st
3
  import requests
4
  import os
5
  import re
6
-
 
7
 
8
  # Environment Setup
9
  HF_API_URL = "https://router.huggingface.co/novita/v3/openai/chat/completions"
@@ -61,7 +62,11 @@ def evaluate_prompt(user_prompt):
61
  else:
62
  return f"Error: {response.status_code} - {response.text}"
63
 
64
-
 
 
 
 
65
  # App UI
66
  st.set_page_config("PromptPolice", page_icon="🚓", layout="centered")
67
  st.markdown("""
@@ -114,9 +119,10 @@ if st.button(":mag_right: Evaluate Prompt"):
114
  </div>
115
  """, unsafe_allow_html=True)
116
 
117
- # Download button
118
- st.download_button("Download Evaluation", result, file_name="evaluation.txt")
119
-
 
120
  # Toast + Balloons + Auto-scroll
121
  st.toast("✅ Evaluation complete!", icon="🤖")
122
  st.balloons()
 
3
  import requests
4
  import os
5
  import re
6
+ from weasyprint import HTML
7
+ from io import BytesIO
8
 
9
  # Environment Setup
10
  HF_API_URL = "https://router.huggingface.co/novita/v3/openai/chat/completions"
 
62
  else:
63
  return f"Error: {response.status_code} - {response.text}"
64
 
65
+ # Function to convert HTML to PDF
66
+ def convert_html_to_pdf(html_content):
67
+ pdf = HTML(string=html_content).write_pdf()
68
+ return pdf
69
+
70
  # App UI
71
  st.set_page_config("PromptPolice", page_icon="🚓", layout="centered")
72
  st.markdown("""
 
119
  </div>
120
  """, unsafe_allow_html=True)
121
 
122
+ # Download button for PDF
123
+ pdf_data = convert_html_to_pdf(result_html)
124
+ st.download_button("Download Evaluation as PDF", pdf_data, file_name="evaluation.pdf")
125
+
126
  # Toast + Balloons + Auto-scroll
127
  st.toast("✅ Evaluation complete!", icon="🤖")
128
  st.balloons()