EdBoy2202 commited on
Commit
8c5b0dd
·
verified ·
1 Parent(s): 5fdb85a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -71
app.py CHANGED
@@ -120,79 +120,94 @@ openai.api_key = st.secrets["GPT_TOKEN"]
120
  # Camera input for taking photo
121
  camera_image = st.camera_input("Take a picture of the car!")
122
 
 
 
 
 
123
  if camera_image is not None:
124
- image = load_image(camera_image)
125
- st.image(image, caption='Captured Image.', use_container_width=True)
 
 
126
 
127
- # Classify the car image
128
- with st.spinner('Analyzing image...'):
129
- car_classifications = classify_image(image)
130
-
131
- if car_classifications:
132
- st.subheader("Car Classification Results:")
133
- for classification in car_classifications:
134
- st.write(f"Model: {classification['label']}")
135
- st.write(f"Confidence: {classification['score']*100:.2f}%")
136
-
137
- # Use the top prediction for further processing
138
- top_prediction = car_classifications[0]['label']
139
- brand, model_name = top_prediction.split(' ', 1)
140
 
141
- st.write(f"Identified Car: {brand} {model_name}")
142
-
143
- # Find the closest match in the CSV
144
- df = load_datasets()
145
- match = find_closest_match(df, brand, model_name)
146
- if match is not None:
147
- st.write("Closest Match Found:")
148
- st.write(f"Make: {match['Make']}")
149
- st.write(f"Model: {match['Model']}")
150
- st.write(f"Year: {match['Year']}")
151
- st.write(f"Price: ${match['Price']}")
152
-
153
- # Get additional information using GPT-3.5-turbo
154
- overview = get_car_overview(match)
155
- st.write("Car Overview:")
156
- st.write(overview)
157
-
158
- # Interactive Price Prediction
159
- st.subheader("Price Prediction Over Time")
160
- selected_years = st.slider("Select range of years for price prediction",
161
- min_value=2000, max_value=2023, value=(2010, 2023))
162
-
163
- years = np.arange(selected_years[0], selected_years[1] + 1)
164
- predicted_prices = []
165
-
166
- for year in years:
167
- user_input = {
168
- 'Make': match['Make'],
169
- 'Model': match['Model'],
170
- 'Condition': match['Condition'],
171
- 'Fuel': match['Fuel'],
172
- 'Title_status': match['Title_status'],
173
- 'Transmission': match['Transmission'],
174
- 'Drive': match['Drive'],
175
- 'Size': match['Size'],
176
- 'Type': match['Type'],
177
- 'Paint_color': match['Paint_color'],
178
- 'Year': year
179
- }
180
-
181
- price = predict_price(model, label_encoders, user_input)
182
- predicted_prices.append(price)
183
-
184
- # Plotting the results
185
- plt.figure(figsize=(10, 5))
186
- plt.plot(years, predicted_prices, marker='o')
187
- plt.title(f"Predicted Price of {match['Make']} {match['Model']} Over Time")
188
- plt.xlabel("Year")
189
- plt.ylabel("Predicted Price ($)")
190
- plt.grid()
191
- st.pyplot(plt)
192
-
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  else:
194
- st.write("No match found in the database.")
195
- else:
196
- st.error("Could not classify the image. Please try again with a different image.")
197
  else:
198
- st.write("Please take a picture of the car to proceed.")
 
 
 
 
 
 
 
120
  # Camera input for taking photo
121
  camera_image = st.camera_input("Take a picture of the car!")
122
 
123
+ # Debug information
124
+ st.write(f"Type of camera_image: {type(camera_image)}")
125
+ st.write(f"Content of camera_image: {camera_image}")
126
+
127
  if camera_image is not None:
128
+ st.write("Image captured successfully.")
129
+ try:
130
+ image = load_image(camera_image)
131
+ st.image(image, caption='Captured Image.', use_container_width=True)
132
 
133
+ # Classify the car image
134
+ with st.spinner('Analyzing image...'):
135
+ car_classifications = classify_image(image)
 
 
 
 
 
 
 
 
 
 
136
 
137
+ if car_classifications:
138
+ st.write("Image classification successful.")
139
+ st.subheader("Car Classification Results:")
140
+ for classification in car_classifications:
141
+ st.write(f"Model: {classification['label']}")
142
+ st.write(f"Confidence: {classification['score']*100:.2f}%")
143
+
144
+ # Use the top prediction for further processing
145
+ top_prediction = car_classifications[0]['label']
146
+ brand, model_name = top_prediction.split(' ', 1)
147
+
148
+ st.write(f"Identified Car: {brand} {model_name}")
149
+
150
+ # Find the closest match in the CSV
151
+ df = load_datasets()
152
+ match = find_closest_match(df, brand, model_name)
153
+ if match is not None:
154
+ st.write("Closest Match Found:")
155
+ st.write(f"Make: {match['Make']}")
156
+ st.write(f"Model: {match['Model']}")
157
+ st.write(f"Year: {match['Year']}")
158
+ st.write(f"Price: ${match['Price']}")
159
+
160
+ # Get additional information using GPT-3.5-turbo
161
+ overview = get_car_overview(match)
162
+ st.write("Car Overview:")
163
+ st.write(overview)
164
+
165
+ # Interactive Price Prediction
166
+ st.subheader("Price Prediction Over Time")
167
+ selected_years = st.slider("Select range of years for price prediction",
168
+ min_value=2000, max_value=2023, value=(2010, 2023))
169
+
170
+ years = np.arange(selected_years[0], selected_years[1] + 1)
171
+ predicted_prices = []
172
+
173
+ for year in years:
174
+ user_input = {
175
+ 'Make': match['Make'],
176
+ 'Model': match['Model'],
177
+ 'Condition': match['Condition'],
178
+ 'Fuel': match['Fuel'],
179
+ 'Title_status': match['Title_status'],
180
+ 'Transmission': match['Transmission'],
181
+ 'Drive': match['Drive'],
182
+ 'Size': match['Size'],
183
+ 'Type': match['Type'],
184
+ 'Paint_color': match['Paint_color'],
185
+ 'Year': year
186
+ }
187
+
188
+ price = predict_price(model, label_encoders, user_input)
189
+ predicted_prices.append(price)
190
+
191
+ # Plotting the results
192
+ plt.figure(figsize=(10, 5))
193
+ plt.plot(years, predicted_prices, marker='o')
194
+ plt.title(f"Predicted Price of {match['Make']} {match['Model']} Over Time")
195
+ plt.xlabel("Year")
196
+ plt.ylabel("Predicted Price ($)")
197
+ plt.grid()
198
+ st.pyplot(plt)
199
+
200
+ else:
201
+ st.write("No match found in the database.")
202
  else:
203
+ st.error("Could not classify the image. Please try again with a different image.")
204
+ except Exception as e:
205
+ st.error(f"Error processing image: {str(e)}")
206
  else:
207
+ st.write("Please take a picture of the car to proceed.")
208
+
209
+ # # Alternative file uploader (for debugging)
210
+ # uploaded_file = st.file_uploader("Or choose a car image", type=["jpg", "jpeg", "png"])
211
+ # if uploaded_file is not None:
212
+ # image = Image.open(uploaded_file)
213
+ # st.image(image, caption='Uploaded Image.', use_container_width=True)