Update app.py
Browse files
app.py
CHANGED
@@ -106,7 +106,27 @@ def query_model(question):
|
|
106 |
if not relevant_segment:
|
107 |
return "Could not find specific information. Please refine your question."
|
108 |
response = generate_response(question, relevant_segment)
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
# Define the welcome message and specific topics the chatbot can provide information about
|
112 |
welcome_message = """
|
|
|
106 |
if not relevant_segment:
|
107 |
return "Could not find specific information. Please refine your question."
|
108 |
response = generate_response(question, relevant_segment)
|
109 |
+
image = get_image_for_response(question)
|
110 |
+
return response, image
|
111 |
+
|
112 |
+
IMAGE_DIRECTORY = "Images"
|
113 |
+
def get_image_for_response(question):
|
114 |
+
"""
|
115 |
+
Retrieve an image based on the response text.
|
116 |
+
"""
|
117 |
+
# Normalize the response text to create a filename
|
118 |
+
file_name = question.lower().replace(" ", "_")
|
119 |
+
image_path = os.path.join(IMAGE_DIRECTORY, file_name + ".png")
|
120 |
+
print(question)
|
121 |
+
print(image_path)
|
122 |
+
|
123 |
+
# Check if the image file exists
|
124 |
+
if os.path.exists(image_path):
|
125 |
+
return Image.open(image_path)
|
126 |
+
else:
|
127 |
+
# Return a default or placeholder image if the file is not found
|
128 |
+
default_image_path = os.path.join(IMAGE_DIRECTORY, "default.png")
|
129 |
+
return Image.open(default_image_path)
|
130 |
|
131 |
# Define the welcome message and specific topics the chatbot can provide information about
|
132 |
welcome_message = """
|