Ajay98 commited on
Commit
0bd2b21
Β·
verified Β·
1 Parent(s): 9d2179d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -77
app.py CHANGED
@@ -294,36 +294,91 @@ 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
- # Gradio Interface
298
- def app():
299
- df = format_salesforce_data()
300
- table_component = None
301
- bar_graph_component = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
 
303
- if df is not None:
304
- table_component = df.to_html(index=False)
305
- bar_graph_image = generate_bar_graph(df)
306
- if bar_graph_image:
307
- bar_graph_component = bar_graph_image
308
 
 
 
309
  return gr.TabbedInterface([
310
  gr.Interface(
311
  fn=process_image,
312
  inputs=[
313
- gr.Image(type="numpy", label="πŸ“„α΄œα΄˜ΚŸα΄α΄€α΄… Ιͺᴍᴀɒᴇ"),
314
- gr.Dropdown(label="πŸ“ŒMode", choices=["ᴇɴᴛʀʏ", "ᴇxΙͺα΄›"], value="Entry"),
315
- gr.Radio(label="πŸ“¦Entry Type", choices=["Sales", "Non-Sales"], value="Sales"),
316
- gr.Number(label="πŸ”’Quantity", value=1, interactive=True),
317
  ],
318
  outputs=[
319
- gr.Text(label="Ιͺᴍᴀɒᴇ α΄…α΄€α΄›α΄€ α΄ Ιͺᴇᴑᴇʀ"),
320
- gr.Text(label="πŸ“οΌ²οΌ₯οΌ³οΌ΅οΌ¬οΌ΄")
321
  ],
322
  title="𝑽𝑬𝑡𝑲𝑨𝑻𝑨𝑹𝑨𝑴𝑨𝑡𝑨 𝑴𝑢𝑻𝑢𝑹𝑺",
323
- description="πŸ“¦πˆππ•π„ππ“πŽπ‘π˜ πŒπ€ππ€π†π„πŒπ„ππ“"
324
  ),
325
  gr.Interface(
326
- fn=lambda: (table_component, bar_graph_component),
327
  inputs=[],
328
  outputs=[
329
  gr.HTML(label="Salesforce Data Table"),
@@ -333,7 +388,8 @@ def app():
333
  description="View structured Salesforce data as a table and bar graph."
334
  )
335
  ], ["Processing", "Salesforce Data"])
336
- # 🎨 Bright and Gradient UI with Updated Coloring
 
337
  css = """
338
  body {
339
  background: linear-gradient(135deg, #282c34, #4b79a1);
@@ -361,25 +417,6 @@ css = """
361
  animation: glow 2s infinite alternate;
362
  }
363
 
364
- @keyframes glow {
365
- from {
366
- text-shadow: 5px 5px 30px rgba(255, 87, 134, 0.6);
367
- }
368
- to {
369
- text-shadow: 6px 6px 40px rgba(255, 54, 90, 1);
370
- }
371
- }
372
-
373
- .gradio-box {
374
- border-radius: 15px;
375
- padding: 25px;
376
- background: linear-gradient(135deg, #6a11cb, #2575fc);
377
- box-shadow: 0px 6px 25px rgba(30, 144, 255, 0.6);
378
- border: 2px solid #6a5acd;
379
- color: white;
380
- font-size: 18px;
381
- }
382
-
383
  .gradio-button {
384
  border-radius: 12px;
385
  padding: 18px 36px;
@@ -396,45 +433,7 @@ css = """
396
  box-shadow: 0px 10px 35px rgba(0, 191, 255, 0.9);
397
  transform: scale(1.1);
398
  }
399
-
400
- .gradio-input {
401
- border-radius: 10px;
402
- padding: 16px;
403
- font-size: 18px;
404
- background: rgba(255, 255, 255, 0.3);
405
- border: 2px solid rgba(0, 123, 255, 0.5);
406
- color: #fff;
407
- transition: 0.3s;
408
- }
409
-
410
- .gradio-input:focus {
411
- border: 2px solid #1e90ff;
412
- outline: none;
413
- box-shadow: 0px 5px 20px rgba(30, 144, 255, 0.6);
414
- }
415
-
416
- .gradio-output {
417
- background: linear-gradient(135deg, #f39c12, #e74c3c);
418
- padding: 22px;
419
- border-radius: 15px;
420
- color: white;
421
- font-size: 20px;
422
- text-align: center;
423
- border: 2px solid #f39c12;
424
- }
425
-
426
- .gradio-file {
427
- background: linear-gradient(135deg, #8e44ad, #3498db);
428
- color: white;
429
- padding: 16px;
430
- border-radius: 15px;
431
- text-align: center;
432
- font-size: 18px;
433
- }
434
  """
435
 
436
-
437
-
438
-
439
  if __name__ == "__main__":
440
- app().launch(share=True)
 
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="πŸ“„ Upload Image"),
369
+ gr.Dropdown(label="πŸ“Œ Mode", choices=["Entry", "Exit"], value="Entry"),
370
+ gr.Radio(label="πŸ“¦ Entry Type", choices=["Sales", "Non-Sales"], value="Sales"),
371
+ gr.Number(label="πŸ”’ Quantity", value=1, interactive=True),
372
  ],
373
  outputs=[
374
+ gr.Text(label="πŸ“ Image Data Viewer"),
375
+ gr.Text(label="πŸ“ Result")
376
  ],
377
  title="𝑽𝑬𝑡𝑲𝑨𝑻𝑨𝑹𝑨𝑴𝑨𝑡𝑨 𝑴𝑢𝑻𝑢𝑹𝑺",
378
+ description="πŸ“¦ πˆππ•π„ππ“πŽπ‘π˜ πŒπ€ππ€π†π„πŒπ„ππ“"
379
  ),
380
  gr.Interface(
381
+ fn=fetch_salesforce_data,
382
  inputs=[],
383
  outputs=[
384
  gr.HTML(label="Salesforce Data Table"),
 
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
  animation: glow 2s infinite alternate;
418
  }
419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  .gradio-button {
421
  border-radius: 12px;
422
  padding: 18px 36px;
 
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)