Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,90 +1,6 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
# Função OCR com PaddleOCR
|
8 |
-
def ocr_with_paddle(img):
|
9 |
-
ocr = PaddleOCR(lang='en', use_angle_cls=True)
|
10 |
-
result = ocr.ocr(img, cls=True)
|
11 |
-
|
12 |
-
finaltext = ''
|
13 |
-
for line in result:
|
14 |
-
for word in line:
|
15 |
-
finaltext += ' ' + word[1][0]
|
16 |
-
return finaltext
|
17 |
-
|
18 |
-
# Função para categorizar despesa (exemplo simples)
|
19 |
-
def categorize_expense(text):
|
20 |
-
if "gas" in text.lower():
|
21 |
-
return "Combustível"
|
22 |
-
elif "restaurant" in text.lower():
|
23 |
-
return "Alimentação"
|
24 |
-
elif "shopping" in text.lower():
|
25 |
-
return "Compras"
|
26 |
-
else:
|
27 |
-
return "Outros"
|
28 |
-
|
29 |
-
# Função para processar a imagem e salvar as informações
|
30 |
-
def process_image(image, method):
|
31 |
-
if method == "PaddleOCR":
|
32 |
-
text = ocr_with_paddle(image)
|
33 |
-
else:
|
34 |
-
raise ValueError("Método OCR não suportado")
|
35 |
-
|
36 |
-
category = categorize_expense(text)
|
37 |
-
return f"Texto reconhecido: {text}\nCategoria: {category}"
|
38 |
-
|
39 |
-
# Função para adicionar projeto
|
40 |
-
def add_project(name, budget, items):
|
41 |
-
project = {
|
42 |
-
"name": name,
|
43 |
-
"budget": budget,
|
44 |
-
"items": items,
|
45 |
-
"spent": 0,
|
46 |
-
"balance": budget
|
47 |
-
}
|
48 |
-
projects.append(project)
|
49 |
-
return f"Projeto {name} adicionado com sucesso."
|
50 |
-
|
51 |
-
# Função para adicionar item ao projeto
|
52 |
-
def add_item_to_project(project_name, item_name, item_cost):
|
53 |
-
for project in projects:
|
54 |
-
if project["name"] == project_name:
|
55 |
-
project["items"].append({"name": item_name, "cost": item_cost})
|
56 |
-
project["balance"] -= item_cost
|
57 |
-
return f"Item {item_name} adicionado ao projeto {project_name}. Saldo atual: {project['balance']}"
|
58 |
-
return "Projeto não encontrado."
|
59 |
-
|
60 |
-
# Inicializando a lista de projetos
|
61 |
-
projects = []
|
62 |
-
|
63 |
-
# Interface Gradio
|
64 |
-
with gr.Blocks() as demo:
|
65 |
-
gr.Markdown("# Controle Financeiro com OCR")
|
66 |
-
|
67 |
-
with gr.Tab("OCR"):
|
68 |
-
img_input = gr.Image(label="Upload da imagem")
|
69 |
-
method_input = gr.Radio(["PaddleOCR"], value="PaddleOCR", label="Método OCR")
|
70 |
-
ocr_output = gr.Textbox(label="Resultado OCR")
|
71 |
-
process_button = gr.Button("Processar Imagem")
|
72 |
-
process_button.click(fn=process_image, inputs=[img_input, method_input], outputs=[ocr_output])
|
73 |
-
|
74 |
-
with gr.Tab("Projetos"):
|
75 |
-
project_name_input = gr.Textbox(label="Nome do Projeto")
|
76 |
-
project_budget_input = gr.Number(label="Orçamento do Projeto")
|
77 |
-
project_items_input = gr.Textbox(label="Itens do Projeto (separados por vírgula e espaço)")
|
78 |
-
add_project_button = gr.Button("Adicionar Projeto")
|
79 |
-
add_project_button.click(fn=add_project, inputs=[project_name_input, project_budget_input, project_items_input], outputs=[gr.Textbox(label="Resultado")])
|
80 |
-
|
81 |
-
project_select = gr.Dropdown(choices=[], label="Selecione o Projeto")
|
82 |
-
item_name_input = gr.Textbox(label="Nome do Item")
|
83 |
-
item_cost_input = gr.Number(label="Custo do Item")
|
84 |
-
add_item_button = gr.Button("Adicionar Item ao Projeto")
|
85 |
-
add_item_button.click(fn=add_item_to_project, inputs=[project_select, item_name_input, item_cost_input], outputs=[gr.Textbox(label="Resultado")])
|
86 |
-
|
87 |
-
project_select.change(lambda: [p["name"] for p in projects], None, project_select)
|
88 |
-
|
89 |
-
# Iniciar a demo
|
90 |
-
demo.launch()
|
|
|
1 |
+
streamlit
|
2 |
+
opencv-python
|
3 |
+
numpy
|
4 |
+
pandas
|
5 |
+
paddlepaddle
|
6 |
+
paddleocr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|