Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,6 +66,7 @@ st.markdown("""
|
|
| 66 |
</div>
|
| 67 |
""", unsafe_allow_html=True)
|
| 68 |
|
|
|
|
| 69 |
def get_or_create_thread_id():
|
| 70 |
doc_ref = db.collection("users").document(user_id)
|
| 71 |
doc = doc_ref.get()
|
|
@@ -76,6 +77,7 @@ def get_or_create_thread_id():
|
|
| 76 |
doc_ref.set({"thread_id": thread.id, "created_at": firestore.SERVER_TIMESTAMP})
|
| 77 |
return thread.id
|
| 78 |
|
|
|
|
| 79 |
def save_message(role, content):
|
| 80 |
db.collection("users").document(user_id).collection("messages").add({
|
| 81 |
"role": role,
|
|
@@ -83,6 +85,7 @@ def save_message(role, content):
|
|
| 83 |
"timestamp": firestore.SERVER_TIMESTAMP
|
| 84 |
})
|
| 85 |
|
|
|
|
| 86 |
def display_chat_history():
|
| 87 |
messages = db.collection("users").document(user_id).collection("messages").order_by("timestamp").stream()
|
| 88 |
assistant_icon_html = "<img src='https://www.carfind.co.za/images/Carfind-Icon.svg' width='20' style='vertical-align:middle;'/>"
|
|
@@ -141,7 +144,7 @@ with tab2:
|
|
| 141 |
st.image(image, caption="Uploaded Image", use_container_width=True)
|
| 142 |
with col2:
|
| 143 |
try:
|
| 144 |
-
# Create a new thread for
|
| 145 |
image_thread = client.beta.threads.create()
|
| 146 |
file_response = client.files.create(file=uploaded_image, purpose="assistants")
|
| 147 |
client.beta.threads.messages.create(
|
|
|
|
| 66 |
</div>
|
| 67 |
""", unsafe_allow_html=True)
|
| 68 |
|
| 69 |
+
# Function to get or create a thread ID for chat
|
| 70 |
def get_or_create_thread_id():
|
| 71 |
doc_ref = db.collection("users").document(user_id)
|
| 72 |
doc = doc_ref.get()
|
|
|
|
| 77 |
doc_ref.set({"thread_id": thread.id, "created_at": firestore.SERVER_TIMESTAMP})
|
| 78 |
return thread.id
|
| 79 |
|
| 80 |
+
# Save message to the Firestore database
|
| 81 |
def save_message(role, content):
|
| 82 |
db.collection("users").document(user_id).collection("messages").add({
|
| 83 |
"role": role,
|
|
|
|
| 85 |
"timestamp": firestore.SERVER_TIMESTAMP
|
| 86 |
})
|
| 87 |
|
| 88 |
+
# Display chat history
|
| 89 |
def display_chat_history():
|
| 90 |
messages = db.collection("users").document(user_id).collection("messages").order_by("timestamp").stream()
|
| 91 |
assistant_icon_html = "<img src='https://www.carfind.co.za/images/Carfind-Icon.svg' width='20' style='vertical-align:middle;'/>"
|
|
|
|
| 144 |
st.image(image, caption="Uploaded Image", use_container_width=True)
|
| 145 |
with col2:
|
| 146 |
try:
|
| 147 |
+
# Create a new thread for image processing
|
| 148 |
image_thread = client.beta.threads.create()
|
| 149 |
file_response = client.files.create(file=uploaded_image, purpose="assistants")
|
| 150 |
client.beta.threads.messages.create(
|