xellDart13 commited on
Commit
40fc766
·
verified ·
1 Parent(s): a985502

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+
5
+ API_URL = "https://ia.nebuia.com/api/v1/integrator/extractor/from/excel"
6
+ API_KEY = "2J7NFWQ-236PGAM-2S9RD3C-2DG54CY"
7
+ API_SECRET = "a47abf97-866b-4154-b29c-346c9b02919e"
8
+
9
+ def send_excel_to_api(file_path, json_structure):
10
+ headers = {
11
+ 'key': API_KEY,
12
+ 'secret': API_SECRET
13
+ }
14
+
15
+ files = {
16
+ 'file': open(file_path, 'rb')
17
+ }
18
+
19
+ data = {
20
+ 'structure': json_structure
21
+ }
22
+
23
+ try:
24
+ response = requests.post(API_URL, headers=headers, files=files, data=data)
25
+
26
+ if response.status_code == 200:
27
+ result = response.json()
28
+ return json.dumps(result, indent=2)
29
+ else:
30
+ return f"Error: Received status code {response.status_code}\n{response.text}"
31
+ except requests.RequestException as e:
32
+ return f"Error sending request: {e}"
33
+ finally:
34
+ files['file'].close()
35
+
36
+ def gradio_interface(file, json_structure):
37
+ if file is None:
38
+ return "Please upload an Excel file."
39
+ return send_excel_to_api(file.name, json_structure)
40
+
41
+ # Create the Gradio interface
42
+ iface = gr.Interface(
43
+ fn=gradio_interface,
44
+ inputs=[
45
+ gr.File(label="Upload Excel File"),
46
+ gr.Code(label="JSON Structure", language="json", lines=15, value='''{
47
+ "activo a corto plazo": {
48
+ "valor inventarios - ejercicio 2023": "",
49
+ "valor inventarios - ejercicio 2022": ""
50
+ },
51
+ "pasivo a corto plazo": {
52
+ "impuestos por pagar - ejercicio 2023": "",
53
+ "impuestos por pagar - ejercicio 2022": ""
54
+ },
55
+ "perdida_del_ejercicio": "",
56
+ "rfc": ""
57
+ }''')
58
+ ],
59
+ outputs=gr.Textbox(label="API Response", lines=10),
60
+ title="NebuIA Excel Structure Extractor",
61
+ description="Upload an Excel file and provide a JSON structure to send to the API."
62
+ )
63
+
64
+ # Launch the interface
65
+ iface.launch()