seawolf2357 commited on
Commit
1862a67
ยท
verified ยท
1 Parent(s): 3bd25bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -9
app.py CHANGED
@@ -3,38 +3,32 @@ import requests
3
  import json
4
  import base64
5
 
6
- # Mathpix์— ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ณด๋‚ด์–ด ์—ฌ๋Ÿฌ ํฌ๋งท์˜ LaTeX ๋ฌธ์ž์—ด์„ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
7
  def get_latex_from_image_all_formats(image):
8
  image_base64 = base64.b64encode(image).decode('utf-8')
9
 
10
- # Mathpix API ์š”์ฒญ ํ—ค๋”
11
  headers = {
12
  "app_id": "arxivgpt_2c0986",
13
  "app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
14
  "Content-Type": "application/json"
15
  }
16
 
17
- # Mathpix API ์š”์ฒญ ๋ฐ”๋””
18
  data = {
19
  "src": f"data:image/jpeg;base64,{image_base64}",
20
  "formats": ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]
21
  }
22
 
23
- # Mathpix API ์š”์ฒญ ๋ณด๋‚ด๊ธฐ
24
  response = requests.post("https://api.mathpix.com/v3/latex", headers=headers, json=data)
25
- response.raise_for_status() # ์š”์ฒญ ์‹คํŒจ ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ
26
 
27
- # ์‘๋‹ต์—์„œ ๊ฐ ํฌ๋งท์˜ LaTeX ์ถ”์ถœ
28
  result = response.json()
29
  formats_results = {f: result.get(f, "์ถ”์ถœ ์‹คํŒจ") for f in data["formats"]}
30
 
31
  return formats_results
32
 
33
- # Gradio ์•ฑ ์ •์˜
34
  def build_gradio_app():
35
  with gr.Blocks() as app:
36
  with gr.Row():
37
- image_input = gr.Image(type="file", label="์ด๋ฏธ์ง€ ์—…๋กœ๋“œ")
38
  submit_button = gr.Button("๋ณ€ํ™˜ํ•˜๊ธฐ")
39
  outputs = {f: gr.Textbox(label=f"{f} ๊ฒฐ๊ณผ") for f in ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]}
40
 
@@ -42,7 +36,6 @@ def build_gradio_app():
42
 
43
  return app
44
 
45
- # Gradio ์•ฑ ์‹คํ–‰
46
  if __name__ == "__main__":
47
  app = build_gradio_app()
48
  app.launch()
 
3
  import json
4
  import base64
5
 
 
6
  def get_latex_from_image_all_formats(image):
7
  image_base64 = base64.b64encode(image).decode('utf-8')
8
 
 
9
  headers = {
10
  "app_id": "arxivgpt_2c0986",
11
  "app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
12
  "Content-Type": "application/json"
13
  }
14
 
 
15
  data = {
16
  "src": f"data:image/jpeg;base64,{image_base64}",
17
  "formats": ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]
18
  }
19
 
 
20
  response = requests.post("https://api.mathpix.com/v3/latex", headers=headers, json=data)
21
+ response.raise_for_status()
22
 
 
23
  result = response.json()
24
  formats_results = {f: result.get(f, "์ถ”์ถœ ์‹คํŒจ") for f in data["formats"]}
25
 
26
  return formats_results
27
 
 
28
  def build_gradio_app():
29
  with gr.Blocks() as app:
30
  with gr.Row():
31
+ image_input = gr.Image(type="filepath", label="์ด๋ฏธ์ง€ ์—…๋กœ๋“œ") # 'file' ํƒ€์ž…์„ 'filepath'๋กœ ๋ณ€๊ฒฝ
32
  submit_button = gr.Button("๋ณ€ํ™˜ํ•˜๊ธฐ")
33
  outputs = {f: gr.Textbox(label=f"{f} ๊ฒฐ๊ณผ") for f in ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]}
34
 
 
36
 
37
  return app
38
 
 
39
  if __name__ == "__main__":
40
  app = build_gradio_app()
41
  app.launch()