VoVanPhuc commited on
Commit
aff8e4d
·
verified ·
1 Parent(s): dc588cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -16,11 +16,17 @@ def call_predict_api(image, private_key=None):
16
  "image": ("src_image.png", src_buffer, "image/png"),
17
  }
18
  headers = {"X-API-Key": os.environ["api_key"]}
19
- response = requests.post(os.environ["endpoint"], files=files, headers=headers)
20
- if response.status_code != 200:
21
- raise Exception(f"API Error: {response.text}")
22
- result = response.json()["result"]
23
- return "Success", result.replace("\n", "\n\n")
 
 
 
 
 
 
24
 
25
  if __name__ == "__main__":
26
  iface = gr.Interface(
@@ -41,7 +47,6 @@ if __name__ == "__main__":
41
  ),
42
  ],
43
  outputs=[
44
- gr.Textbox(label="Status", type="text", visible=False),
45
  gr.Markdown(label="Result")
46
  ],
47
  title="BBC-OCR",
 
16
  "image": ("src_image.png", src_buffer, "image/png"),
17
  }
18
  headers = {"X-API-Key": os.environ["api_key"]}
19
+ response = requests.get(os.environ["endpoint"],
20
+ files=files,
21
+ headers=headers,
22
+ stream=True
23
+ )
24
+ accumulated = ""
25
+ for line in response:
26
+ if line:
27
+ accumulated += line.decode("utf-8").replace("\n", "\n\n")
28
+ yield accumulated
29
+
30
 
31
  if __name__ == "__main__":
32
  iface = gr.Interface(
 
47
  ),
48
  ],
49
  outputs=[
 
50
  gr.Markdown(label="Result")
51
  ],
52
  title="BBC-OCR",