Spaces:
Sleeping
Sleeping
Commit
路
4789a30
1
Parent(s):
60c9fb8
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
|
| 4 |
|
| 5 |
# Esta funci贸n env铆a una solicitud POST a la API de Labelary para convertir ZPL a PDF
|
| 6 |
def convert_zpl_to_pdf(zpl_string):
|
|
@@ -12,10 +12,12 @@ def convert_zpl_to_pdf(zpl_string):
|
|
| 12 |
response = requests.post(labelary_api, headers=headers, data=zpl_string.encode('utf-8'), stream=True)
|
| 13 |
|
| 14 |
if response.status_code == 200:
|
| 15 |
-
#
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
else:
|
| 18 |
-
# Si la solicitud fall贸, lanzamos una excepci贸n con el error
|
| 19 |
raise Exception(f"Error durante la conversi贸n de ZPL a PDF: {response.text}")
|
| 20 |
|
| 21 |
# Crear una interfaz Gradio
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import tempfile
|
| 4 |
|
| 5 |
# Esta funci贸n env铆a una solicitud POST a la API de Labelary para convertir ZPL a PDF
|
| 6 |
def convert_zpl_to_pdf(zpl_string):
|
|
|
|
| 12 |
response = requests.post(labelary_api, headers=headers, data=zpl_string.encode('utf-8'), stream=True)
|
| 13 |
|
| 14 |
if response.status_code == 200:
|
| 15 |
+
# Escribimos el contenido PDF en un archivo temporal
|
| 16 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as temp_file:
|
| 17 |
+
temp_file.write(response.content)
|
| 18 |
+
# Guardamos la ruta del archivo temporal para devolverla
|
| 19 |
+
return temp_file.name
|
| 20 |
else:
|
|
|
|
| 21 |
raise Exception(f"Error durante la conversi贸n de ZPL a PDF: {response.text}")
|
| 22 |
|
| 23 |
# Crear una interfaz Gradio
|