Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
125 |
-
|
|
|
|
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
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 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
else:
|
194 |
-
st.
|
195 |
-
|
196 |
-
st.error("
|
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)
|