Spaces:
Runtime error
Runtime error
uploaded csv file
Browse files- AI Car-Test - complete data.csv +0 -0
- app.py +24 -15
AI Car-Test - complete data.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
app.py
CHANGED
@@ -22,7 +22,6 @@ class Bot():
|
|
22 |
self.available_car_models = None
|
23 |
self.set_prompts()
|
24 |
|
25 |
-
|
26 |
def set_prompts(self):
|
27 |
self.eng_system_prompt = f"""You are a salesman in a car dealership. You only recommend cars that are currently in stock.
|
28 |
To access the cars in stock (inventory) in your dealership use the padnas dataframe query method like this:
|
@@ -40,7 +39,7 @@ Use contains() instead of equals() to search brands, models and categories.
|
|
40 |
Note that the code snippet above is illustrative and not meant to be executed by the user. It demonstrates how you internally interact with the car inventory to know which cars are in stock.
|
41 |
If you are going to search for cars output only the query and no other text."""
|
42 |
|
43 |
-
self.ger_system_prompt =
|
44 |
Um auf die im Autohaus vorhandenen Autos (Inventar) zuzugreifen, verwenden Sie die padnas-Dataframe-Abfrage-Methode wie folgt:
|
45 |
|
46 |
```
|
@@ -77,16 +76,20 @@ Wenn Sie nach Autos suchen, geben Sie nur die Abfrage und keinen anderen Text au
|
|
77 |
return []
|
78 |
|
79 |
def process_file(self, file, history):
|
80 |
-
|
81 |
-
|
82 |
-
if file
|
83 |
-
if
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
85 |
else:
|
86 |
-
|
87 |
-
return history
|
88 |
|
89 |
-
df = pd.read_csv(
|
90 |
# drop all rows with at least one NaN value
|
91 |
# only use columns marke modell kategorie kilomeret preis
|
92 |
df = df[["marke", "modell2", "kategorie", "kilometer", "preis", "grundfarbe"]]
|
@@ -105,7 +108,9 @@ Wenn Sie nach Autos suchen, geben Sie nur die Abfrage und keinen anderen Text au
|
|
105 |
self.available_car_models = df["marke"].unique()
|
106 |
print(self.available_car_models)
|
107 |
if self.lang == "English":
|
108 |
-
df = df.rename(
|
|
|
|
|
109 |
|
110 |
df = df.loc[:, ~df.columns.duplicated()]
|
111 |
|
@@ -131,6 +136,7 @@ Wenn Sie nach Autos suchen, geben Sie nur die Abfrage und keinen anderen Text au
|
|
131 |
openai.api_key = query
|
132 |
|
133 |
if self.df is None:
|
|
|
134 |
if self.lang == "English":
|
135 |
history.append((None, "Please upload a csv file. (This might take a few minutes)"))
|
136 |
else:
|
@@ -143,7 +149,7 @@ Wenn Sie nach Autos suchen, geben Sie nur die Abfrage und keinen anderen Text au
|
|
143 |
if not passed:
|
144 |
return history
|
145 |
|
146 |
-
messages=[]
|
147 |
# add messages from history
|
148 |
for q, response in history:
|
149 |
if q:
|
@@ -196,9 +202,11 @@ Wenn Sie nach Autos suchen, geben Sie nur die Abfrage und keinen anderen Text au
|
|
196 |
print(query_line)
|
197 |
if result.empty:
|
198 |
if self.lang == "English":
|
199 |
-
messages.insert(-1, {"role": "system",
|
|
|
200 |
else:
|
201 |
-
messages.insert(-1, {"role": "system",
|
|
|
202 |
else:
|
203 |
# take only 50 random rows
|
204 |
if len(result) > 50:
|
@@ -209,7 +217,8 @@ Wenn Sie nach Autos suchen, geben Sie nur die Abfrage und keinen anderen Text au
|
|
209 |
if self.lang == "English":
|
210 |
messages.insert(-1, {"role": "system", "content": f"Advice cars from this list:\n\n{result}"})
|
211 |
else:
|
212 |
-
messages.insert(-1,
|
|
|
213 |
|
214 |
response = openai.ChatCompletion.create(
|
215 |
model="gpt-3.5-turbo",
|
|
|
22 |
self.available_car_models = None
|
23 |
self.set_prompts()
|
24 |
|
|
|
25 |
def set_prompts(self):
|
26 |
self.eng_system_prompt = f"""You are a salesman in a car dealership. You only recommend cars that are currently in stock.
|
27 |
To access the cars in stock (inventory) in your dealership use the padnas dataframe query method like this:
|
|
|
39 |
Note that the code snippet above is illustrative and not meant to be executed by the user. It demonstrates how you internally interact with the car inventory to know which cars are in stock.
|
40 |
If you are going to search for cars output only the query and no other text."""
|
41 |
|
42 |
+
self.ger_system_prompt = f"""Sie sind ein Verkäufer in einem Autohaus. Sie empfehlen nur Autos, die derzeit auf Lager sind.
|
43 |
Um auf die im Autohaus vorhandenen Autos (Inventar) zuzugreifen, verwenden Sie die padnas-Dataframe-Abfrage-Methode wie folgt:
|
44 |
|
45 |
```
|
|
|
76 |
return []
|
77 |
|
78 |
def process_file(self, file, history):
|
79 |
+
# check if file is a string
|
80 |
+
filename = file
|
81 |
+
if not isinstance(file, str):
|
82 |
+
# throw error if file is not csv
|
83 |
+
if file.name.split(".")[-1] != "csv":
|
84 |
+
if lang == "English":
|
85 |
+
history.append((None, "Please upload a csv file"))
|
86 |
+
else:
|
87 |
+
history.append((None, "Bitte laden Sie eine csv-Datei hoch"))
|
88 |
+
return history
|
89 |
else:
|
90 |
+
filename = file.name
|
|
|
91 |
|
92 |
+
df = pd.read_csv(filename)
|
93 |
# drop all rows with at least one NaN value
|
94 |
# only use columns marke modell kategorie kilomeret preis
|
95 |
df = df[["marke", "modell2", "kategorie", "kilometer", "preis", "grundfarbe"]]
|
|
|
108 |
self.available_car_models = df["marke"].unique()
|
109 |
print(self.available_car_models)
|
110 |
if self.lang == "English":
|
111 |
+
df = df.rename(
|
112 |
+
columns={"marke": "brand", "modell": "model", "kategorie": "category", "kilometer": "kilometer",
|
113 |
+
"preis": "price", "grundfarbe": "color"})
|
114 |
|
115 |
df = df.loc[:, ~df.columns.duplicated()]
|
116 |
|
|
|
136 |
openai.api_key = query
|
137 |
|
138 |
if self.df is None:
|
139 |
+
return self.process_file("./AI Car-Test - complete data.csv", []), False
|
140 |
if self.lang == "English":
|
141 |
history.append((None, "Please upload a csv file. (This might take a few minutes)"))
|
142 |
else:
|
|
|
149 |
if not passed:
|
150 |
return history
|
151 |
|
152 |
+
messages = []
|
153 |
# add messages from history
|
154 |
for q, response in history:
|
155 |
if q:
|
|
|
202 |
print(query_line)
|
203 |
if result.empty:
|
204 |
if self.lang == "English":
|
205 |
+
messages.insert(-1, {"role": "system",
|
206 |
+
"content": "No results for this query. Help user narrow their preferences."})
|
207 |
else:
|
208 |
+
messages.insert(-1, {"role": "system",
|
209 |
+
"content": "Für diese Abfrage gibt es keine Ergebnisse. Helfen Sie dem Benutzer, seine Präferenzen einzugrenzen."})
|
210 |
else:
|
211 |
# take only 50 random rows
|
212 |
if len(result) > 50:
|
|
|
217 |
if self.lang == "English":
|
218 |
messages.insert(-1, {"role": "system", "content": f"Advice cars from this list:\n\n{result}"})
|
219 |
else:
|
220 |
+
messages.insert(-1,
|
221 |
+
{"role": "system", "content": f"Empfehlung von Autos aus dieser Liste:\n\n{result}"})
|
222 |
|
223 |
response = openai.ChatCompletion.create(
|
224 |
model="gpt-3.5-turbo",
|