Update app.py
Browse files
app.py
CHANGED
|
@@ -436,6 +436,8 @@ def classify_image(image):
|
|
| 436 |
st.error(f"Classification error: {e}")
|
| 437 |
return None
|
| 438 |
|
|
|
|
|
|
|
| 439 |
def get_car_overview(brand, model, year):
|
| 440 |
try:
|
| 441 |
prompt = f"Provide an overview of the following car:\nYear: {year}\nMake: {brand}\nModel: {model}\n"
|
|
@@ -492,25 +494,27 @@ def generate_gpt_response(prompt, dataset):
|
|
| 492 |
st.dataframe(dataset_response) # Show results to the user
|
| 493 |
return f"I found some information in our dataset about {make.title()} {model.title() if model else ''}. Please see the details above."
|
| 494 |
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
)
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
model="gpt-3.5-turbo",
|
| 508 |
-
messages=messages,
|
| 509 |
-
max_tokens=500,
|
| 510 |
-
temperature=0.7,
|
| 511 |
-
)
|
| 512 |
-
|
| 513 |
-
return response['choices'][0]['message']['content']
|
| 514 |
|
| 515 |
# --- Assistant Section ---
|
| 516 |
def create_assistant_section(dataset):
|
|
|
|
| 436 |
st.error(f"Classification error: {e}")
|
| 437 |
return None
|
| 438 |
|
| 439 |
+
|
| 440 |
+
|
| 441 |
def get_car_overview(brand, model, year):
|
| 442 |
try:
|
| 443 |
prompt = f"Provide an overview of the following car:\nYear: {year}\nMake: {brand}\nModel: {model}\n"
|
|
|
|
| 494 |
st.dataframe(dataset_response) # Show results to the user
|
| 495 |
return f"I found some information in our dataset about {make.title()} {model.title() if model else ''}. Please see the details above."
|
| 496 |
|
| 497 |
+
try:
|
| 498 |
+
openai.api_key = "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" # Replace with your API key
|
| 499 |
+
system_message = {
|
| 500 |
+
"role": "system",
|
| 501 |
+
"content": "You are a helpful car shopping assistant. Provide concise car recommendations or pricing estimates. Keep responses focused and brief."
|
| 502 |
+
}
|
| 503 |
+
messages = [
|
| 504 |
+
system_message,
|
| 505 |
+
{"role": "user", "content": f"Provide a brief response about: {prompt}"}
|
| 506 |
+
]
|
| 507 |
+
|
| 508 |
+
response = openai.ChatCompletion.create(
|
| 509 |
+
model="gpt-3.5-turbo",
|
| 510 |
+
messages=messages,
|
| 511 |
+
max_tokens=300, # Reduced from 500
|
| 512 |
+
temperature=0.7,
|
| 513 |
)
|
| 514 |
+
|
| 515 |
+
return response['choices'][0]['message']['content']
|
| 516 |
+
except Exception as e:
|
| 517 |
+
return f"I apologize, but I encountered an error: {str(e)}. Could you please rephrase your question or make it more specific?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 518 |
|
| 519 |
# --- Assistant Section ---
|
| 520 |
def create_assistant_section(dataset):
|