Spaces:
Runtime error
Runtime error
ziyadsuper2017
commited on
Commit
•
50b3dd7
1
Parent(s):
d5a9ec5
Update app.py
Browse files
app.py
CHANGED
@@ -67,23 +67,26 @@ def clear_conversation():
|
|
67 |
st.session_state['file_uploader_key'] = str(uuid.uuid4())
|
68 |
|
69 |
def display_chat_history():
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
87 |
|
88 |
# --- Send Message Function ---
|
89 |
def send_message():
|
@@ -126,6 +129,8 @@ def send_message():
|
|
126 |
st.session_state.user_input = ''
|
127 |
st.session_state.uploaded_files = []
|
128 |
st.session_state.file_uploader_key = str(uuid.uuid4())
|
|
|
|
|
129 |
display_chat_history()
|
130 |
|
131 |
# --- User Input Area ---
|
@@ -141,7 +146,7 @@ with col2:
|
|
141 |
send_button = st.button(
|
142 |
"Send",
|
143 |
on_click=send_message,
|
144 |
-
type="primary"
|
145 |
)
|
146 |
|
147 |
# --- File Uploader ---
|
|
|
67 |
st.session_state['file_uploader_key'] = str(uuid.uuid4())
|
68 |
|
69 |
def display_chat_history():
|
70 |
+
chat_container = st.empty() # Create an empty container to hold the chat history
|
71 |
+
with chat_container.container(): # Use a container to update the chat history
|
72 |
+
for entry in st.session_state['chat_history']:
|
73 |
+
role = entry["role"]
|
74 |
+
parts = entry["parts"][0]
|
75 |
+
if 'text' in parts:
|
76 |
+
st.markdown(f"**{role.title()}:** {parts['text']}")
|
77 |
+
elif 'data' in parts:
|
78 |
+
mime_type = parts.get('mime_type', '')
|
79 |
+
if mime_type.startswith('image'):
|
80 |
+
st.image(Image.open(io.BytesIO(base64.b64decode(parts['data']))),
|
81 |
+
caption='Uploaded Image', use_column_width=True)
|
82 |
+
elif mime_type == 'application/pdf':
|
83 |
+
st.write("**PDF Content:**")
|
84 |
+
pdf_reader = PyPDF2.PdfReader(io.BytesIO(base64.b64decode(parts['data'])))
|
85 |
+
for page_num in range(len(pdf_reader.pages)):
|
86 |
+
page = pdf_reader.pages[page_num]
|
87 |
+
st.write(page.extract_text())
|
88 |
+
elif mime_type.startswith('video'):
|
89 |
+
st.video(io.BytesIO(base64.b64decode(parts['data'])))
|
90 |
|
91 |
# --- Send Message Function ---
|
92 |
def send_message():
|
|
|
129 |
st.session_state.user_input = ''
|
130 |
st.session_state.uploaded_files = []
|
131 |
st.session_state.file_uploader_key = str(uuid.uuid4())
|
132 |
+
|
133 |
+
# Update the chat history display
|
134 |
display_chat_history()
|
135 |
|
136 |
# --- User Input Area ---
|
|
|
146 |
send_button = st.button(
|
147 |
"Send",
|
148 |
on_click=send_message,
|
149 |
+
type="primary"
|
150 |
)
|
151 |
|
152 |
# --- File Uploader ---
|