Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from PIL import Image, ImageEnhance
|
|
| 4 |
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
import re
|
|
|
|
| 7 |
from simple_salesforce import Salesforce
|
| 8 |
|
| 9 |
# Attribute mappings: readable names to Salesforce API names
|
|
@@ -118,13 +119,12 @@ def extract_text(image):
|
|
| 118 |
extracted_text.append(line[1][0])
|
| 119 |
return "\n".join(extracted_text)
|
| 120 |
|
| 121 |
-
# Function to find product name from the predefined list
|
| 122 |
def match_product_name(text):
|
| 123 |
-
# Normalize text and product names
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
return product_name
|
| 128 |
return None
|
| 129 |
|
| 130 |
# Function to find attributes and their values
|
|
@@ -242,7 +242,7 @@ def process_image(image, quantity, mode):
|
|
| 242 |
return "No attributes found in the image.", None
|
| 243 |
|
| 244 |
numbered_output = "\n".join(
|
| 245 |
-
[f"{key.replace('__c','')}: {value}" for key, value in attributes.items()]
|
| 246 |
)
|
| 247 |
|
| 248 |
file_path = save_to_excel(attributes)
|
|
@@ -270,10 +270,9 @@ interface = gr.Interface(
|
|
| 270 |
gr.Text(label="Image Data Viewer"),
|
| 271 |
gr.File(label="Data Storage Manager")
|
| 272 |
],
|
| 273 |
-
title="Processing -
|
| 274 |
-
description="Process images
|
| 275 |
)
|
| 276 |
|
| 277 |
if __name__ == "__main__":
|
| 278 |
interface.launch(share=True)
|
| 279 |
-
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
import re
|
| 7 |
+
from fuzzywuzzy import process
|
| 8 |
from simple_salesforce import Salesforce
|
| 9 |
|
| 10 |
# Attribute mappings: readable names to Salesforce API names
|
|
|
|
| 119 |
extracted_text.append(line[1][0])
|
| 120 |
return "\n".join(extracted_text)
|
| 121 |
|
| 122 |
+
# Function to find product name from the predefined list using fuzzy matching
|
| 123 |
def match_product_name(text):
|
| 124 |
+
# Normalize text and match against product names
|
| 125 |
+
best_match, score = process.extractOne(text, PRODUCT_NAMES)
|
| 126 |
+
if score >= 80: # Match threshold
|
| 127 |
+
return best_match
|
|
|
|
| 128 |
return None
|
| 129 |
|
| 130 |
# Function to find attributes and their values
|
|
|
|
| 242 |
return "No attributes found in the image.", None
|
| 243 |
|
| 244 |
numbered_output = "\n".join(
|
| 245 |
+
[f"{key.replace('__c', '').replace('_', ' ').title()}: {value}" for key, value in attributes.items()]
|
| 246 |
)
|
| 247 |
|
| 248 |
file_path = save_to_excel(attributes)
|
|
|
|
| 270 |
gr.Text(label="Image Data Viewer"),
|
| 271 |
gr.File(label="Data Storage Manager")
|
| 272 |
],
|
| 273 |
+
title="Processing - VENKATA RAMANA MOTORS",
|
| 274 |
+
description="Process images for Entry or Exit mode to update stock.",
|
| 275 |
)
|
| 276 |
|
| 277 |
if __name__ == "__main__":
|
| 278 |
interface.launch(share=True)
|
|
|