IAMTFRMZA commited on
Commit
fbddc5a
Β·
verified Β·
1 Parent(s): 30c6dd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -93,10 +93,10 @@ def display_chat_history():
93
  else:
94
  st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-assistant'>{assistant_icon_html} <strong>Carfind Assistant:</strong> {data['content']}</div>", unsafe_allow_html=True)
95
 
96
- # Tabs
97
-
98
  tab1, tab2 = st.tabs(["AI Chat", "What car is that?"])
99
 
 
100
  with tab1:
101
  input_col, clear_col = st.columns([9, 1])
102
  with input_col:
@@ -131,8 +131,9 @@ with tab1:
131
  time.sleep(0.5)
132
  st.rerun()
133
 
 
134
  with tab2:
135
- uploaded_image = st.file_uploader("Upload an image of a car and let Ai identify it for you", type=["jpg", "jpeg", "png"])
136
  if uploaded_image:
137
  col1, col2 = st.columns([1.2, 1.8])
138
  with col1:
@@ -140,15 +141,19 @@ with tab2:
140
  st.image(image, caption="Uploaded Image", use_container_width=True)
141
  with col2:
142
  try:
 
143
  image_thread = client.beta.threads.create()
144
  file_response = client.files.create(file=uploaded_image, purpose="assistants")
145
  client.beta.threads.messages.create(
146
  thread_id=image_thread.id,
147
  role="user",
148
- content=[
149
- {"type": "image_file", "image_file": {"file_id": file_response.id}},
150
- {"type": "text", "text": "Identify this car image and respond using the markdown output format shown in your instructions β€” include all sections (🟒 Identified Vehicle, πŸ“‹ Details, 🚘 Overview, πŸ”Ž Recommended For) without follow-ups or links."}
151
- ]
 
 
 
152
  )
153
  run = client.beta.threads.runs.create(thread_id=image_thread.id, assistant_id=assistant_id)
154
  with st.spinner("πŸ” Analyzing image and identifying the car..."):
@@ -162,4 +167,4 @@ with tab2:
162
  st.success("βœ… Identification Complete")
163
  st.markdown(f"<div class='car-spec-output'>{assistant_message}</div>", unsafe_allow_html=True)
164
  except Exception as e:
165
- st.error(f"❌ Error during image analysis: {str(e)}")
 
93
  else:
94
  st.markdown(f"<div class='stChatMessage' data-testid='stChatMessage-assistant'>{assistant_icon_html} <strong>Carfind Assistant:</strong> {data['content']}</div>", unsafe_allow_html=True)
95
 
96
+ # Tabs for Chat and Car Identification
 
97
  tab1, tab2 = st.tabs(["AI Chat", "What car is that?"])
98
 
99
+ # Tab 1: AI Chat
100
  with tab1:
101
  input_col, clear_col = st.columns([9, 1])
102
  with input_col:
 
131
  time.sleep(0.5)
132
  st.rerun()
133
 
134
+ # Tab 2: "What Car is That?"
135
  with tab2:
136
+ uploaded_image = st.file_uploader("Upload an image of a car and let AI identify it for you", type=["jpg", "jpeg", "png"])
137
  if uploaded_image:
138
  col1, col2 = st.columns([1.2, 1.8])
139
  with col1:
 
141
  st.image(image, caption="Uploaded Image", use_container_width=True)
142
  with col2:
143
  try:
144
+ # Create a new thread for the image processing
145
  image_thread = client.beta.threads.create()
146
  file_response = client.files.create(file=uploaded_image, purpose="assistants")
147
  client.beta.threads.messages.create(
148
  thread_id=image_thread.id,
149
  role="user",
150
+ content=[{
151
+ "type": "image_file",
152
+ "image_file": {"file_id": file_response.id}
153
+ }, {
154
+ "type": "text",
155
+ "text": "Identify this car image and respond using the markdown output format shown in your instructions β€” include all sections (🟒 Identified Vehicle, πŸ“‹ Details, 🚘 Overview, πŸ”Ž Recommended For) without follow-ups or links."
156
+ }]
157
  )
158
  run = client.beta.threads.runs.create(thread_id=image_thread.id, assistant_id=assistant_id)
159
  with st.spinner("πŸ” Analyzing image and identifying the car..."):
 
167
  st.success("βœ… Identification Complete")
168
  st.markdown(f"<div class='car-spec-output'>{assistant_message}</div>", unsafe_allow_html=True)
169
  except Exception as e:
170
+ st.error(f"❌ Error during image analysis: {str(e)}")