Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,42 +7,28 @@ from langchain_core.runnables.history import RunnableWithMessageHistory
|
|
| 7 |
from langchain_groq import ChatGroq
|
| 8 |
import os
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# Define the image description function
|
| 17 |
-
def image_description(image):
|
| 18 |
-
inputs = processor(images=image, return_tensors="pt")
|
| 19 |
-
out = model.generate(**inputs)
|
| 20 |
-
return processor.decode(out[0], skip_special_tokens=True)
|
| 21 |
-
|
| 22 |
-
# Define the problem categorization function
|
| 23 |
-
def problem_categorization(problem_description):
|
| 24 |
-
department_keywords = {
|
| 25 |
-
"Cleaning": [
|
| 26 |
-
"trash", "garbage", "dirt", "dirty", "litter", "unclean", "filthy", "sanitize",
|
| 27 |
-
"disinfect", "hygiene", "cleanliness", "stain", "spill", "clutter", "pest",
|
| 28 |
-
"bedbugs", "roaches", "dust", "graffiti"
|
| 29 |
-
],
|
| 30 |
-
"Electrical": [
|
| 31 |
-
"power", "electric", "light", "lamp", "flicker", "outage", "wiring", "circuit",
|
| 32 |
-
"switch", "socket", "fan", "air conditioner", "generator", "fuse", "overload",
|
| 33 |
-
"short circuit", "malfunction", "burnt", "spark", "battery"
|
| 34 |
-
],
|
| 35 |
-
"Plumbing": [
|
| 36 |
-
"leak", "pipe", "flood", "drain", "clog", "sewage", "overflow", "toilet", "sink",
|
| 37 |
-
"basin", "shower", "tap", "faucet", "plumber", "gasket", "water pressure", "burst",
|
| 38 |
-
"plumbing", "seepage", "moisture", "damp", "fixture", "water supply", "clogging"
|
| 39 |
-
]
|
| 40 |
-
}
|
| 41 |
-
for department, terms in department_keywords.items():
|
| 42 |
-
if any(term in problem_description for term in terms):
|
| 43 |
-
return department
|
| 44 |
-
return "NA"
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Define the chatbot model
|
| 47 |
# os.environ["GROQ_API_KEY"] = "GROQQQ"
|
| 48 |
chat_model = ChatGroq(model="llama3-8b-8192")
|
|
@@ -139,14 +125,8 @@ chain = prompt | chat_model
|
|
| 139 |
def handle_input(image, text, session_id):
|
| 140 |
if image:
|
| 141 |
# Handle image input
|
| 142 |
-
image_desc =
|
| 143 |
-
|
| 144 |
-
if category=='NA':
|
| 145 |
-
response="Please upload a better image"
|
| 146 |
-
else:
|
| 147 |
-
response=f"Your request has been forwarded to the {category} department"
|
| 148 |
-
if text:
|
| 149 |
-
response+=f"With the description: {text}"
|
| 150 |
else:
|
| 151 |
# Handle text input
|
| 152 |
if text=='':
|
|
|
|
| 7 |
from langchain_groq import ChatGroq
|
| 8 |
import os
|
| 9 |
|
| 10 |
+
def category(image):
|
| 11 |
+
model = genai.GenerativeModel(model_name="gemini-1.5-pro")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
prompt = '''
|
| 14 |
+
"Analyze the given image and identify three distinct problems. For each problem, provide a brief description highlighting the issue. Additionally, offer a general description of the image, including key elements, objects, or the overall scene depicted. Follow the format below:
|
| 15 |
+
|
| 16 |
+
**General Description:**
|
| 17 |
+
[Provide a brief summary of the image, mentioning the main elements or scene.]
|
| 18 |
+
|
| 19 |
+
**Problem 1:**
|
| 20 |
+
- **Description:** [Briefly describe the first issue identified in the image.]
|
| 21 |
+
|
| 22 |
+
**Problem 2:**
|
| 23 |
+
- **Description:** [Briefly describe the second issue identified in the image.]
|
| 24 |
+
|
| 25 |
+
**Problem 3:**
|
| 26 |
+
- **Description:** [Briefly describe the third issue identified in the image.]"
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
response = model.generate_content([prompt, image])
|
| 30 |
+
|
| 31 |
+
print(response.text)
|
| 32 |
# Define the chatbot model
|
| 33 |
# os.environ["GROQ_API_KEY"] = "GROQQQ"
|
| 34 |
chat_model = ChatGroq(model="llama3-8b-8192")
|
|
|
|
| 125 |
def handle_input(image, text, session_id):
|
| 126 |
if image:
|
| 127 |
# Handle image input
|
| 128 |
+
image_desc = category(image)
|
| 129 |
+
return image_desc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
else:
|
| 131 |
# Handle text input
|
| 132 |
if text=='':
|