TomatoFT commited on
Commit
47f08a4
1 Parent(s): 899f25a

Fix: Debuging in the app code

Browse files
Files changed (1) hide show
  1. app.py +16 -40
app.py CHANGED
@@ -1,48 +1,24 @@
1
  import gradio as gr
2
- import PIL
3
- import numpy as np
4
- from PIL import Image, ImageDraw, ImageFont
5
- from translate import Translator
6
 
7
- def translate_text(text, src_lang='en', dest_lang='vi'):
8
- translator = Translator(to_lang=dest_lang, from_lang=src_lang)
9
- translation = translator.translate(text)
10
- return translation
11
 
12
- def process_image(image):
13
- # Convert the uploaded image data to a PIL Image
14
- image = Image.open(image).convert('RGB')
15
- image.save('temp.jpg')
16
 
17
- # Sample code to perform OCR and draw translated text (replace with your logic)
18
- # Simulated results for demonstration purposes
19
- result = [
20
- ([(100, 100), (200, 100), (200, 200), (100, 200)], ("Hello, how are you?", 0.95))
21
- ]
22
 
23
- draw = PIL.ImageDraw.Draw(image)
24
- for i, box in enumerate(result):
25
- text = translate_text(box[1][0])
26
- box = np.array(box[0]).astype(np.int32)
27
- xmin = min(box[:, 0])
28
- ymin = min(box[:, 1])
29
- xmax = max(box[:, 0])
30
- ymax = max(box[:, 1])
31
- draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
32
- draw.text((xmin + 40, ymin + 40), f"{text}", fill="black", font=ImageFont.load_default())
33
-
34
- # Save the processed image
35
- processed_image_path = 'processed_image.jpg'
36
- image.save(processed_image_path)
37
- return processed_image_path
38
-
39
- iface = gr.Interface(
40
- fn=process_image,
41
- inputs=gr.Image(type="filepath", label="Upload Image"),
42
- outputs="image",
43
- title="OCR Translation App",
44
- description="Upload an image and see the processed image with translated text."
45
  )
46
 
47
  if __name__ == "__main__":
48
- iface.launch(share=True)
 
 
1
  import gradio as gr
2
+ import os
 
 
 
3
 
 
 
 
 
4
 
5
+ def image_mod(image):
6
+ return image.rotate(45)
 
 
7
 
 
 
 
 
 
8
 
9
+ demo = gr.Interface(
10
+ image_mod,
11
+ gr.Image(type="pil"),
12
+ "image",
13
+ flagging_options=["blurry", "incorrect", "other"],
14
+ examples=[
15
+ os.path.join(os.path.dirname(__file__), "images/cheetah1.jpg"),
16
+ os.path.join(os.path.dirname(__file__), "images/lion.jpg"),
17
+ os.path.join(os.path.dirname(__file__), "images/logo.png"),
18
+ os.path.join(os.path.dirname(__file__), "images/tower.jpg"),
19
+ ],
 
 
 
 
 
 
 
 
 
 
 
20
  )
21
 
22
  if __name__ == "__main__":
23
+ demo.launch()
24
+