Spaces:
Sleeping
Sleeping
chips
commited on
Commit
Β·
a687c6a
1
Parent(s):
9acac5c
a lot of changes
Browse files
app.py
CHANGED
|
@@ -2,23 +2,22 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from typing import List, Dict
|
| 5 |
-
from flask import Flask, send_from_directory
|
| 6 |
-
import threading
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
flask_thread.start()
|
| 22 |
|
| 23 |
class CSVViewer:
|
| 24 |
def __init__(self, csv_path: str):
|
|
@@ -76,10 +75,10 @@ def create_page_view(page_num: int):
|
|
| 76 |
product_code = page_data['product_info']['Product Code']
|
| 77 |
|
| 78 |
# Find matching image file
|
| 79 |
-
image_files = [f for f in os.listdir('thumbs') if f.startswith(product_code)]
|
| 80 |
if image_files:
|
| 81 |
-
# Use
|
| 82 |
-
image_path = f"
|
| 83 |
print(f"Found image: {image_path}")
|
| 84 |
else:
|
| 85 |
image_path = None
|
|
@@ -110,20 +109,60 @@ def create_page_view(page_num: int):
|
|
| 110 |
ai_key = key + '_AI'
|
| 111 |
ai_value = page_data['ai_data'].get(ai_key, '')
|
| 112 |
|
| 113 |
-
#
|
| 114 |
-
if
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# Add row with comparison
|
| 122 |
html += f"<tr style='background-color: {row_color};'>"
|
| 123 |
html += f"<td style='width: 150px;'>{key}</td>"
|
| 124 |
-
html += f"<td>{
|
| 125 |
-
html += f"<td>{
|
| 126 |
-
html += f"<td style='color: {
|
| 127 |
html += "</tr>"
|
| 128 |
|
| 129 |
html += "</table></div>"
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from typing import List, Dict
|
|
|
|
|
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# Create static directory if it doesn't exist
|
| 8 |
+
if not os.path.exists('static'):
|
| 9 |
+
os.makedirs('static')
|
| 10 |
|
| 11 |
+
# Move thumbs directory into static if it exists
|
| 12 |
+
if os.path.exists('thumbs'):
|
| 13 |
+
import shutil
|
| 14 |
+
if not os.path.exists('static/thumbs'):
|
| 15 |
+
shutil.move('thumbs', 'static/')
|
| 16 |
+
else:
|
| 17 |
+
# If static/thumbs already exists, merge the contents
|
| 18 |
+
for file in os.listdir('thumbs'):
|
| 19 |
+
shutil.move(os.path.join('thumbs', file), 'static/thumbs/')
|
| 20 |
+
os.rmdir('thumbs')
|
|
|
|
| 21 |
|
| 22 |
class CSVViewer:
|
| 23 |
def __init__(self, csv_path: str):
|
|
|
|
| 75 |
product_code = page_data['product_info']['Product Code']
|
| 76 |
|
| 77 |
# Find matching image file
|
| 78 |
+
image_files = [f for f in os.listdir('static/thumbs') if f.startswith(product_code)]
|
| 79 |
if image_files:
|
| 80 |
+
# Use Gradio's static file serving
|
| 81 |
+
image_path = f"/static/thumbs/{image_files[0]}"
|
| 82 |
print(f"Found image: {image_path}")
|
| 83 |
else:
|
| 84 |
image_path = None
|
|
|
|
| 109 |
ai_key = key + '_AI'
|
| 110 |
ai_value = page_data['ai_data'].get(ai_key, '')
|
| 111 |
|
| 112 |
+
# Skip if AI value is empty
|
| 113 |
+
if not ai_value.strip():
|
| 114 |
+
continue
|
| 115 |
+
|
| 116 |
+
# Clean up values by removing brackets and quotes
|
| 117 |
+
orig_value = str(orig_value).strip('[]').strip('"').strip()
|
| 118 |
+
ai_value = str(ai_value).strip('[]').strip('"').strip()
|
| 119 |
+
|
| 120 |
+
# Handle array values
|
| 121 |
+
try:
|
| 122 |
+
# Try to parse as arrays
|
| 123 |
+
orig_items = [item.strip() for item in orig_value.split(',') if item.strip()]
|
| 124 |
+
ai_items = [item.strip() for item in ai_value.split(',') if item.strip()]
|
| 125 |
+
|
| 126 |
+
# Check if all original items are in AI items
|
| 127 |
+
if all(item.lower() in [x.lower() for x in ai_items] for item in orig_items):
|
| 128 |
+
if len(ai_items) > len(orig_items):
|
| 129 |
+
status = "β All and more"
|
| 130 |
+
status_color = "#4CAF50"
|
| 131 |
+
row_color = "#e8f5e9"
|
| 132 |
+
else:
|
| 133 |
+
status = "β Match"
|
| 134 |
+
status_color = "#4CAF50"
|
| 135 |
+
row_color = "#e8f5e9"
|
| 136 |
+
else:
|
| 137 |
+
status = "β Mismatch"
|
| 138 |
+
status_color = "#f44336"
|
| 139 |
+
row_color = "#ffebee"
|
| 140 |
+
|
| 141 |
+
# Format the values nicely
|
| 142 |
+
orig_display = ', '.join(orig_items)
|
| 143 |
+
ai_display = ', '.join(ai_items)
|
| 144 |
+
|
| 145 |
+
except:
|
| 146 |
+
# Handle non-array values
|
| 147 |
+
if orig_value.lower() == ai_value.lower():
|
| 148 |
+
status = "β Match"
|
| 149 |
+
status_color = "#4CAF50"
|
| 150 |
+
row_color = "#e8f5e9"
|
| 151 |
+
orig_display = orig_value
|
| 152 |
+
ai_display = ai_value
|
| 153 |
+
else:
|
| 154 |
+
status = "β Mismatch"
|
| 155 |
+
status_color = "#f44336"
|
| 156 |
+
row_color = "#ffebee"
|
| 157 |
+
orig_display = orig_value
|
| 158 |
+
ai_display = ai_value
|
| 159 |
|
| 160 |
# Add row with comparison
|
| 161 |
html += f"<tr style='background-color: {row_color};'>"
|
| 162 |
html += f"<td style='width: 150px;'>{key}</td>"
|
| 163 |
+
html += f"<td>{orig_display}</td>"
|
| 164 |
+
html += f"<td>{ai_display}</td>"
|
| 165 |
+
html += f"<td style='color: {status_color}; font-weight: bold;'>{status}</td>"
|
| 166 |
html += "</tr>"
|
| 167 |
|
| 168 |
html += "</table></div>"
|