EdBoy2202 commited on
Commit
522b9eb
·
verified ·
1 Parent(s): 2ff9835

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -1,13 +1,24 @@
1
  import streamlit as st
 
2
  from PIL import Image
3
  from transformers import AutoFeatureExtractor, AutoModelForImageClassification
4
  import torch
5
- from datetime import datetime
6
  import openai
7
 
8
  # Initialize OpenAI API key
9
  openai.api_key = st.secrets["GPT_TOKEN"]
10
 
 
 
 
 
 
 
 
 
 
 
 
11
  # Function to classify the car image using pre-trained model
12
  def classify_image(image):
13
  try:
@@ -51,6 +62,9 @@ def get_car_overview(brand, model, year):
51
  st.title("Auto Appraise")
52
  st.write("Upload a car image or take a picture to get its brand, model, and overview!")
53
 
 
 
 
54
  # Get the session state
55
  if 'image' not in st.session_state:
56
  st.session_state.image = None
@@ -105,6 +119,14 @@ if st.session_state.image is not None:
105
  st.write("Car Overview:")
106
  st.write(overview)
107
 
 
 
 
 
 
 
 
 
108
  else:
109
  st.error("Could not classify the image. Please try again with a different image.")
110
  else:
 
1
  import streamlit as st
2
+ import pandas as pd
3
  from PIL import Image
4
  from transformers import AutoFeatureExtractor, AutoModelForImageClassification
5
  import torch
 
6
  import openai
7
 
8
  # Initialize OpenAI API key
9
  openai.api_key = st.secrets["GPT_TOKEN"]
10
 
11
+ # Dataset loading function with caching
12
+ @st.cache_data
13
+ def load_datasets():
14
+ try:
15
+ with st.spinner('Loading dataset...'):
16
+ original_data = pd.read_csv('CTP_Model1.csv', low_memory=False)
17
+ return original_data
18
+ except Exception as e:
19
+ st.error(f"Error loading dataset: {str(e)}")
20
+ raise e
21
+
22
  # Function to classify the car image using pre-trained model
23
  def classify_image(image):
24
  try:
 
62
  st.title("Auto Appraise")
63
  st.write("Upload a car image or take a picture to get its brand, model, and overview!")
64
 
65
+ # Load dataset
66
+ dataset = load_datasets()
67
+
68
  # Get the session state
69
  if 'image' not in st.session_state:
70
  st.session_state.image = None
 
119
  st.write("Car Overview:")
120
  st.write(overview)
121
 
122
+ # Match the car make and model to a record in the dataset
123
+ matched_entry = dataset[(dataset['Make'] == make_name) & (dataset['model'] == model_name)]
124
+
125
+ if not matched_entry.empty:
126
+ st.write("Matched Entry from Dataset:")
127
+ st.write(matched_entry)
128
+ else:
129
+ st.write("No matching entry found in the dataset.")
130
  else:
131
  st.error("Could not classify the image. Please try again with a different image.")
132
  else: