Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
from paddleocr import PaddleOCR
|
| 3 |
-
import gradio as gr
|
| 4 |
-
from simple_salesforce import Salesforce
|
| 5 |
-
import pandas as pd
|
| 6 |
-
import plotly.express as px
|
| 7 |
-
import re
|
| 8 |
-
from fuzzywuzzy import process
|
| 9 |
-
|
| 10 |
-
# Load Salesforce Credentials Securely
|
| 11 |
-
SALESFORCE_USERNAME = os.getenv("SALESFORCE_USERNAME")
|
| 12 |
-
SALESFORCE_PASSWORD = os.getenv("SALESFORCE_PASSWORD")
|
| 13 |
-
SALESFORCE_SECURITY_TOKEN = os.getenv("SALESFORCE_SECURITY_TOKEN")
|
| 14 |
-
import os
|
| 15 |
-
from paddleocr import PaddleOCR
|
| 16 |
from PIL import Image
|
| 17 |
import gradio as gr
|
| 18 |
import requests
|
|
@@ -116,6 +103,11 @@ PRODUCT_NAMES = [
|
|
| 116 |
"mono block pumps"
|
| 117 |
]
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
#π§ Initialize PaddleOCR
|
| 120 |
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
| 121 |
|
|
@@ -294,91 +286,36 @@ def process_image(image, mode, entry_type, quantity):
|
|
| 294 |
numbered_output = "\n".join([f"{key}: {value}" for key, value in attributes.items()])
|
| 295 |
return f"Extracted Text:\n{extracted_text}\n\nAttributes and Values:\n{numbered_output}", message
|
| 296 |
|
| 297 |
-
import os
|
| 298 |
-
from paddleocr import PaddleOCR
|
| 299 |
-
import gradio as gr
|
| 300 |
-
from simple_salesforce import Salesforce
|
| 301 |
-
import pandas as pd
|
| 302 |
-
import plotly.express as px
|
| 303 |
-
import re
|
| 304 |
-
from fuzzywuzzy import process
|
| 305 |
-
|
| 306 |
-
# Initialize PaddleOCR
|
| 307 |
-
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
| 308 |
-
|
| 309 |
-
# Salesforce Credentials
|
| 310 |
-
SALESFORCE_USERNAME = os.getenv("SALESFORCE_USERNAME")
|
| 311 |
-
SALESFORCE_PASSWORD = os.getenv("SALESFORCE_PASSWORD")
|
| 312 |
-
SALESFORCE_SECURITY_TOKEN = os.getenv("SALESFORCE_SECURITY_TOKEN")
|
| 313 |
-
|
| 314 |
-
# Fetch Salesforce Data & Generate Graph
|
| 315 |
-
def fetch_salesforce_data():
|
| 316 |
-
try:
|
| 317 |
-
sf = Salesforce(username=SALESFORCE_USERNAME, password=SALESFORCE_PASSWORD, security_token=SALESFORCE_SECURITY_TOKEN)
|
| 318 |
-
query = "SELECT Product_Name__c, Current_Stocks__c FROM Inventory_Management__c"
|
| 319 |
-
response = sf.query_all(query)
|
| 320 |
-
|
| 321 |
-
if not response['records']:
|
| 322 |
-
return "No data found in Salesforce.", None
|
| 323 |
-
|
| 324 |
-
df = pd.DataFrame(response["records"]).drop(columns=['attributes'], errors='ignore')
|
| 325 |
-
df.rename(columns={"Product_Name__c": "Product Name", "Current_Stocks__c": "Stock Quantity"}, inplace=True)
|
| 326 |
-
|
| 327 |
-
fig = px.bar(
|
| 328 |
-
df,
|
| 329 |
-
x="Product Name",
|
| 330 |
-
y="Stock Quantity",
|
| 331 |
-
title="Stock Distribution",
|
| 332 |
-
labels={"Product Name": "Products", "Stock Quantity": "Quantity"},
|
| 333 |
-
hover_data=["Product Name", "Stock Quantity"],
|
| 334 |
-
color="Stock Quantity",
|
| 335 |
-
color_continuous_scale='Viridis'
|
| 336 |
-
)
|
| 337 |
-
|
| 338 |
-
fig.update_traces(
|
| 339 |
-
texttemplate='%{x}: %{y}',
|
| 340 |
-
textposition='outside',
|
| 341 |
-
hovertemplate='%{x}: %{y} units'
|
| 342 |
-
)
|
| 343 |
-
|
| 344 |
-
fig.update_layout(
|
| 345 |
-
hovermode='closest',
|
| 346 |
-
xaxis_title="Product",
|
| 347 |
-
yaxis_title="Stock Quantity",
|
| 348 |
-
template="plotly_dark",
|
| 349 |
-
showlegend=False
|
| 350 |
-
)
|
| 351 |
-
|
| 352 |
-
return df.to_html(index=False), fig.to_image(format="png")
|
| 353 |
-
|
| 354 |
-
except Exception as e:
|
| 355 |
-
return f"Error fetching Salesforce data: {str(e)}", None
|
| 356 |
-
|
| 357 |
-
# Image Processing Function
|
| 358 |
-
def process_image(image, mode, entry_type, quantity):
|
| 359 |
-
extracted_text = "Sample Extracted Text" # Placeholder for OCR result
|
| 360 |
-
return f"Extracted Text:\n{extracted_text}\n\nProcessed successfully."
|
| 361 |
-
|
| 362 |
# Gradio Interface
|
| 363 |
def app():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
return gr.TabbedInterface([
|
| 365 |
gr.Interface(
|
| 366 |
fn=process_image,
|
| 367 |
inputs=[
|
| 368 |
-
gr.Image(type="numpy", label="
|
| 369 |
-
gr.Dropdown(label="π
|
| 370 |
-
gr.Radio(label="π¦
|
| 371 |
-
gr.Number(label="π’
|
| 372 |
],
|
| 373 |
outputs=[
|
| 374 |
-
gr.Text(label="
|
| 375 |
-
gr.Text(label="
|
| 376 |
],
|
| 377 |
title="π½π¬π΅π²π¨π»π¨πΉπ¨π΄π¨π΅π¨ π΄πΆπ»πΆπΉπΊ",
|
| 378 |
-
description="
|
| 379 |
),
|
| 380 |
gr.Interface(
|
| 381 |
-
fn=
|
| 382 |
inputs=[],
|
| 383 |
outputs=[
|
| 384 |
gr.HTML(label="Salesforce Data Table"),
|
|
@@ -388,8 +325,7 @@ def app():
|
|
| 388 |
description="View structured Salesforce data as a table and bar graph."
|
| 389 |
)
|
| 390 |
], ["Processing", "Salesforce Data"])
|
| 391 |
-
|
| 392 |
-
# π¨ Bright and Gradient UI with Updated Coloring
|
| 393 |
css = """
|
| 394 |
body {
|
| 395 |
background: linear-gradient(135deg, #282c34, #4b79a1);
|
|
@@ -417,6 +353,25 @@ css = """
|
|
| 417 |
animation: glow 2s infinite alternate;
|
| 418 |
}
|
| 419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
.gradio-button {
|
| 421 |
border-radius: 12px;
|
| 422 |
padding: 18px 36px;
|
|
@@ -433,7 +388,45 @@ css = """
|
|
| 433 |
box-shadow: 0px 10px 35px rgba(0, 191, 255, 0.9);
|
| 434 |
transform: scale(1.1);
|
| 435 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
"""
|
| 437 |
|
|
|
|
|
|
|
|
|
|
| 438 |
if __name__ == "__main__":
|
| 439 |
-
app().launch(share=True)
|
|
|
|
| 1 |
import os
|
| 2 |
from paddleocr import PaddleOCR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
|
|
|
| 103 |
"mono block pumps"
|
| 104 |
]
|
| 105 |
|
| 106 |
+
#π Salesforce credentials
|
| 107 |
+
SALESFORCE_USERNAME = "venkatramana@sandbox.com"
|
| 108 |
+
SALESFORCE_PASSWORD = "Venkat12345@"
|
| 109 |
+
SALESFORCE_SECURITY_TOKEN = "GhcJJmjBEefdnukJoz4CAQlR"
|
| 110 |
+
|
| 111 |
#π§ Initialize PaddleOCR
|
| 112 |
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
| 113 |
|
|
|
|
| 286 |
numbered_output = "\n".join([f"{key}: {value}" for key, value in attributes.items()])
|
| 287 |
return f"Extracted Text:\n{extracted_text}\n\nAttributes and Values:\n{numbered_output}", message
|
| 288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
# Gradio Interface
|
| 290 |
def app():
|
| 291 |
+
df = format_salesforce_data()
|
| 292 |
+
table_component = None
|
| 293 |
+
bar_graph_component = None
|
| 294 |
+
|
| 295 |
+
if df is not None:
|
| 296 |
+
table_component = df.to_html(index=False)
|
| 297 |
+
bar_graph_image = generate_bar_graph(df)
|
| 298 |
+
if bar_graph_image:
|
| 299 |
+
bar_graph_component = bar_graph_image
|
| 300 |
+
|
| 301 |
return gr.TabbedInterface([
|
| 302 |
gr.Interface(
|
| 303 |
fn=process_image,
|
| 304 |
inputs=[
|
| 305 |
+
gr.Image(type="numpy", label="πα΄α΄Κα΄α΄α΄
Ιͺα΄α΄Ι’α΄"),
|
| 306 |
+
gr.Dropdown(label="πMode", choices=["α΄Ι΄α΄ΚΚ", "α΄xΙͺα΄"], value="Entry"),
|
| 307 |
+
gr.Radio(label="π¦Entry Type", choices=["Sales", "Non-Sales"], value="Sales"),
|
| 308 |
+
gr.Number(label="π’Quantity", value=1, interactive=True),
|
| 309 |
],
|
| 310 |
outputs=[
|
| 311 |
+
gr.Text(label="Ιͺα΄α΄Ι’α΄ α΄
α΄α΄α΄ α΄ Ιͺα΄α΄‘α΄Κ"),
|
| 312 |
+
gr.Text(label="ποΌ²οΌ₯οΌ³οΌ΅οΌ¬οΌ΄")
|
| 313 |
],
|
| 314 |
title="π½π¬π΅π²π¨π»π¨πΉπ¨π΄π¨π΅π¨ π΄πΆπ»πΆπΉπΊ",
|
| 315 |
+
description="π¦πππππππππ ππππππππππ"
|
| 316 |
),
|
| 317 |
gr.Interface(
|
| 318 |
+
fn=lambda: (table_component, bar_graph_component),
|
| 319 |
inputs=[],
|
| 320 |
outputs=[
|
| 321 |
gr.HTML(label="Salesforce Data Table"),
|
|
|
|
| 325 |
description="View structured Salesforce data as a table and bar graph."
|
| 326 |
)
|
| 327 |
], ["Processing", "Salesforce Data"])
|
| 328 |
+
# π¨ Bright and Gradient UI with Updated Coloring
|
|
|
|
| 329 |
css = """
|
| 330 |
body {
|
| 331 |
background: linear-gradient(135deg, #282c34, #4b79a1);
|
|
|
|
| 353 |
animation: glow 2s infinite alternate;
|
| 354 |
}
|
| 355 |
|
| 356 |
+
@keyframes glow {
|
| 357 |
+
from {
|
| 358 |
+
text-shadow: 5px 5px 30px rgba(255, 87, 134, 0.6);
|
| 359 |
+
}
|
| 360 |
+
to {
|
| 361 |
+
text-shadow: 6px 6px 40px rgba(255, 54, 90, 1);
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
.gradio-box {
|
| 366 |
+
border-radius: 15px;
|
| 367 |
+
padding: 25px;
|
| 368 |
+
background: linear-gradient(135deg, #6a11cb, #2575fc);
|
| 369 |
+
box-shadow: 0px 6px 25px rgba(30, 144, 255, 0.6);
|
| 370 |
+
border: 2px solid #6a5acd;
|
| 371 |
+
color: white;
|
| 372 |
+
font-size: 18px;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
.gradio-button {
|
| 376 |
border-radius: 12px;
|
| 377 |
padding: 18px 36px;
|
|
|
|
| 388 |
box-shadow: 0px 10px 35px rgba(0, 191, 255, 0.9);
|
| 389 |
transform: scale(1.1);
|
| 390 |
}
|
| 391 |
+
|
| 392 |
+
.gradio-input {
|
| 393 |
+
border-radius: 10px;
|
| 394 |
+
padding: 16px;
|
| 395 |
+
font-size: 18px;
|
| 396 |
+
background: rgba(255, 255, 255, 0.3);
|
| 397 |
+
border: 2px solid rgba(0, 123, 255, 0.5);
|
| 398 |
+
color: #fff;
|
| 399 |
+
transition: 0.3s;
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
.gradio-input:focus {
|
| 403 |
+
border: 2px solid #1e90ff;
|
| 404 |
+
outline: none;
|
| 405 |
+
box-shadow: 0px 5px 20px rgba(30, 144, 255, 0.6);
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
.gradio-output {
|
| 409 |
+
background: linear-gradient(135deg, #f39c12, #e74c3c);
|
| 410 |
+
padding: 22px;
|
| 411 |
+
border-radius: 15px;
|
| 412 |
+
color: white;
|
| 413 |
+
font-size: 20px;
|
| 414 |
+
text-align: center;
|
| 415 |
+
border: 2px solid #f39c12;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
.gradio-file {
|
| 419 |
+
background: linear-gradient(135deg, #8e44ad, #3498db);
|
| 420 |
+
color: white;
|
| 421 |
+
padding: 16px;
|
| 422 |
+
border-radius: 15px;
|
| 423 |
+
text-align: center;
|
| 424 |
+
font-size: 18px;
|
| 425 |
+
}
|
| 426 |
"""
|
| 427 |
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
|
| 431 |
if __name__ == "__main__":
|
| 432 |
+
app().launch(share=True)
|