Spaces:
Sleeping
Sleeping
Upload 9 files
Browse files- DATA/consumuri.xlsx +0 -0
- app.py +37 -0
- backend/__init__.py +1 -0
- backend/__pycache__/__init__.cpython-311.pyc +0 -0
- backend/__pycache__/__init__.cpython-39.pyc +0 -0
- backend/__pycache__/cantitati_consum.cpython-311.pyc +0 -0
- backend/__pycache__/cantitati_consum.cpython-39.pyc +0 -0
- backend/cantitati_consum.py +66 -0
- requirements.txt +6 -0
DATA/consumuri.xlsx
ADDED
|
Binary file (58.1 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from backend import cantitati_piesa
|
| 5 |
+
|
| 6 |
+
with gr.Blocks() as consum:
|
| 7 |
+
gr.Markdown(
|
| 8 |
+
"# CPA Logistics")
|
| 9 |
+
|
| 10 |
+
with gr.Tabs():
|
| 11 |
+
with gr.TabItem(label="Nr.piese "):
|
| 12 |
+
gr.Markdown(
|
| 13 |
+
"Aici poti sa calulezi nr. total de unitati ce iti trbuie din fiecare produs."
|
| 14 |
+
"Te rog ai grija ca fisierul de input nume_fisier.xlsx sa:\n"
|
| 15 |
+
" \n - incepa direct cu denuirea coloanelor \n - sa aiba un format constant \n - uite mai jos un exmplu:")
|
| 16 |
+
exemplu_01 = gr.File(label="Exemplu fisier de input:", value="DATA/consumuri.xlsx")
|
| 17 |
+
with gr.Row():
|
| 18 |
+
with gr.Column(scale=1, min_width=400):
|
| 19 |
+
|
| 20 |
+
file_material_a = gr.File(label="Introdu aici lista de consumuri:" )
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
id_componente = gr.Text(label="Nume colaona id:", value="Denumire")
|
| 24 |
+
cantitate = gr.Text(label="Nume colaona cantitate:", value="Cantitate")
|
| 25 |
+
|
| 26 |
+
msc_button = gr.Button("Calculeaza cantitatea totala din fiecare produs:")
|
| 27 |
+
|
| 28 |
+
cantitati_totale = gr.Text(label="Cantitati totale:")
|
| 29 |
+
cantitati_totale_xlsx = gr.File(label="Cntitati xlsx:")
|
| 30 |
+
|
| 31 |
+
msc_button.click(cantitati_piesa,
|
| 32 |
+
inputs=[file_material_a,id_componente, cantitate],
|
| 33 |
+
outputs=[cantitati_totale, cantitati_totale_xlsx])
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
consum.launch(share=False)
|
backend/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .cantitati_consum import cantitati_piesa
|
backend/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (247 Bytes). View file
|
|
|
backend/__pycache__/__init__.cpython-39.pyc
ADDED
|
Binary file (215 Bytes). View file
|
|
|
backend/__pycache__/cantitati_consum.cpython-311.pyc
ADDED
|
Binary file (1.62 kB). View file
|
|
|
backend/__pycache__/cantitati_consum.cpython-39.pyc
ADDED
|
Binary file (989 Bytes). View file
|
|
|
backend/cantitati_consum.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import random
|
| 3 |
+
import datetime
|
| 4 |
+
|
| 5 |
+
# # Specify the file path of the XLS document
|
| 6 |
+
# file_path = 'consumuri.xlsx'
|
| 7 |
+
# # Read the XLS file
|
| 8 |
+
# data = pd.read_excel(file_path)
|
| 9 |
+
# data = data.fillna('<nimic>')
|
| 10 |
+
pd.set_option('display.max_rows', None) # Display all rows
|
| 11 |
+
pd.set_option('display.max_columns', None) # Display all columns
|
| 12 |
+
pd.set_option('display.width', 1000) # Set the display width for showing more information
|
| 13 |
+
pd.set_option('display.colheader_justify', 'center') # Center justify column headers
|
| 14 |
+
pd.set_option('display.precision', 3) # Set precision for decimal values
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def format_items(dictionary):
|
| 18 |
+
"pretty string"
|
| 19 |
+
formatted_string = "Item Details:\n"
|
| 20 |
+
for key, value in dictionary.items():
|
| 21 |
+
formatted_string += f"{key}: {value}\n"
|
| 22 |
+
return formatted_string
|
| 23 |
+
|
| 24 |
+
def cantitati_piesa(file, denumire_id, cantitate):
|
| 25 |
+
"""
|
| 26 |
+
Calculeaza cate piese trebuie sa fie facute de fiecare data cand intlaneste id d epiese ii aduaga cantitatea..
|
| 27 |
+
:param file:
|
| 28 |
+
:type file:
|
| 29 |
+
:param denumire_id:
|
| 30 |
+
:type denumire_id:
|
| 31 |
+
:param cantitate:
|
| 32 |
+
:type cantitate:
|
| 33 |
+
:return:
|
| 34 |
+
:rtype:
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
data=pd.read_excel(file)
|
| 38 |
+
products = {}
|
| 39 |
+
for index, row in data.iterrows():
|
| 40 |
+
denumire = row[denumire_id]
|
| 41 |
+
if denumire not in ['Consumuri', '<nimic>']:
|
| 42 |
+
|
| 43 |
+
if denumire not in products:
|
| 44 |
+
products[denumire] = row[cantitate]
|
| 45 |
+
else:
|
| 46 |
+
products[denumire] += row[cantitate]
|
| 47 |
+
p={"produs":[], "cantitate":[]}
|
| 48 |
+
for k in products.keys():
|
| 49 |
+
p["produs"].append(k)
|
| 50 |
+
p["cantitate"].append(products[k])
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
df=pd.DataFrame.from_dict(p)
|
| 54 |
+
|
| 55 |
+
# Generate a random number and get the current date
|
| 56 |
+
random_number = random.randint(1000, 9999)
|
| 57 |
+
current_date = datetime.datetime.now().strftime("%Y%m%d")
|
| 58 |
+
filename = f"{file.name}_cantitate_{current_date}_{random_number}.xlsx"
|
| 59 |
+
df.to_excel(filename, index=False)
|
| 60 |
+
# Generate a summary string for display
|
| 61 |
+
summary_string = "Canitati produse:\n" + "\n".join(f"{prod}: {qty}" for prod, qty in products.items())
|
| 62 |
+
|
| 63 |
+
# Return the summary string and the path to the Excel file
|
| 64 |
+
return summary_string, filename
|
| 65 |
+
|
| 66 |
+
return df
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.26.0
|
| 2 |
+
pandas ==2.2
|
| 3 |
+
Requests==2.31.0
|
| 4 |
+
scipy==1.13.0
|
| 5 |
+
torch==2.1.1
|
| 6 |
+
openpyxl
|