Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ from PIL import Image
|
|
6 |
import io
|
7 |
import os
|
8 |
|
9 |
-
# Enhanced 3D style CSS
|
10 |
css = """
|
11 |
footer {
|
12 |
visibility: hidden;
|
@@ -52,10 +51,32 @@ app_id = os.getenv("app_id")
|
|
52 |
app_key = os.getenv("app_key")
|
53 |
app_url = os.getenv("app_url")
|
54 |
|
55 |
-
# Rest of your functions remain the same
|
56 |
def get_latex_from_image_all_formats(image):
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
def build_gradio_app(css=css):
|
61 |
with gr.Blocks(css=css) as demo:
|
@@ -65,9 +86,17 @@ def build_gradio_app(css=css):
|
|
65 |
image_input = gr.Image(type="pil", label="Upload Image")
|
66 |
|
67 |
def process_and_output(image):
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
submit_button = gr.Button("Convert", elem_classes="custom-button")
|
73 |
outputs = gr.Textbox(label="Output")
|
|
|
6 |
import io
|
7 |
import os
|
8 |
|
|
|
9 |
css = """
|
10 |
footer {
|
11 |
visibility: hidden;
|
|
|
51 |
app_key = os.getenv("app_key")
|
52 |
app_url = os.getenv("app_url")
|
53 |
|
|
|
54 |
def get_latex_from_image_all_formats(image):
|
55 |
+
try:
|
56 |
+
if image is None:
|
57 |
+
return {"text": "No image provided"}
|
58 |
+
|
59 |
+
buffered = io.BytesIO()
|
60 |
+
image.save(buffered, format="JPEG")
|
61 |
+
image_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
62 |
+
|
63 |
+
headers = {
|
64 |
+
"app_id": app_id,
|
65 |
+
"app_key": app_key,
|
66 |
+
"Content-Type": "application/json"
|
67 |
+
}
|
68 |
+
|
69 |
+
data = {
|
70 |
+
"src": f"data:image/jpeg;base64,{image_base64}",
|
71 |
+
"formats": ["text"]
|
72 |
+
}
|
73 |
+
|
74 |
+
response = requests.post(app_url, headers=headers, json=data)
|
75 |
+
response.raise_for_status()
|
76 |
+
|
77 |
+
return response.json()
|
78 |
+
except Exception as e:
|
79 |
+
return {"text": f"Error: {str(e)}"}
|
80 |
|
81 |
def build_gradio_app(css=css):
|
82 |
with gr.Blocks(css=css) as demo:
|
|
|
86 |
image_input = gr.Image(type="pil", label="Upload Image")
|
87 |
|
88 |
def process_and_output(image):
|
89 |
+
try:
|
90 |
+
if image is None:
|
91 |
+
return "Please upload an image"
|
92 |
+
|
93 |
+
latex_result = get_latex_from_image_all_formats(image)
|
94 |
+
if latex_result is None:
|
95 |
+
return "Error processing image"
|
96 |
+
|
97 |
+
return latex_result.get("text", "No result")
|
98 |
+
except Exception as e:
|
99 |
+
return f"Error: {str(e)}"
|
100 |
|
101 |
submit_button = gr.Button("Convert", elem_classes="custom-button")
|
102 |
outputs = gr.Textbox(label="Output")
|