Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from datetime import datetime
|
|
9 |
from streamlit.components.v1 import html
|
10 |
from PIL import Image
|
11 |
import re
|
|
|
12 |
|
13 |
# Set up the Anthropic client
|
14 |
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
@@ -18,8 +19,11 @@ if "chat_history" not in st.session_state:
|
|
18 |
st.session_state.chat_history = []
|
19 |
|
20 |
# Function to get file download link
|
21 |
-
def get_download_link(
|
22 |
-
|
|
|
|
|
|
|
23 |
return f'<a href="data:file/txt;base64,{b64}" download="{file_name}">Download {file_name}</a>'
|
24 |
|
25 |
# Function to generate filename
|
@@ -54,6 +58,23 @@ def display_glossary_entity(k):
|
|
54 |
links_md = ' '.join([f"[{emoji}]({url(k)})" for emoji, url in search_urls.items()])
|
55 |
st.markdown(f"**{k}** <small>{links_md}</small>", unsafe_allow_html=True)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# Streamlit app
|
58 |
def main():
|
59 |
st.title("Claude 3.5 Sonnet API Demo")
|
|
|
9 |
from streamlit.components.v1 import html
|
10 |
from PIL import Image
|
11 |
import re
|
12 |
+
from urllib.parse import quote
|
13 |
|
14 |
# Set up the Anthropic client
|
15 |
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
|
|
19 |
st.session_state.chat_history = []
|
20 |
|
21 |
# Function to get file download link
|
22 |
+
def get_download_link(file_path):
|
23 |
+
with open(file_path, "rb") as file:
|
24 |
+
contents = file.read()
|
25 |
+
b64 = base64.b64encode(contents).decode()
|
26 |
+
file_name = os.path.basename(file_path)
|
27 |
return f'<a href="data:file/txt;base64,{b64}" download="{file_name}">Download {file_name}</a>'
|
28 |
|
29 |
# Function to generate filename
|
|
|
58 |
links_md = ' '.join([f"[{emoji}]({url(k)})" for emoji, url in search_urls.items()])
|
59 |
st.markdown(f"**{k}** <small>{links_md}</small>", unsafe_allow_html=True)
|
60 |
|
61 |
+
# Function to create zip of files
|
62 |
+
def create_zip_of_files(files):
|
63 |
+
import zipfile
|
64 |
+
zip_name = "all_files.zip"
|
65 |
+
with zipfile.ZipFile(zip_name, 'w') as zipf:
|
66 |
+
for file in files:
|
67 |
+
zipf.write(file)
|
68 |
+
return zip_name
|
69 |
+
|
70 |
+
# Function to get zip download link
|
71 |
+
def get_zip_download_link(zip_file):
|
72 |
+
with open(zip_file, 'rb') as f:
|
73 |
+
data = f.read()
|
74 |
+
b64 = base64.b64encode(data).decode()
|
75 |
+
href = f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
76 |
+
return href
|
77 |
+
|
78 |
# Streamlit app
|
79 |
def main():
|
80 |
st.title("Claude 3.5 Sonnet API Demo")
|