Spaces:
Runtime error
Runtime error
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import base64
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def run(image):
|
| 9 |
+
if image is None:
|
| 10 |
+
raise gr.Error('No input image')
|
| 11 |
+
|
| 12 |
+
buffer = BytesIO()
|
| 13 |
+
input_image.save(buffer, format='PNG')
|
| 14 |
+
img_str = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
| 15 |
+
return img_str
|
| 16 |
+
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
with gr.Row():
|
| 19 |
+
with gr.Column():
|
| 20 |
+
image = gr.Image(type='pil', interactive=True)
|
| 21 |
+
submit = gr.Button()
|
| 22 |
+
output_text = gr.Textbox(interactive=False)
|
| 23 |
+
|
| 24 |
+
submit.click(
|
| 25 |
+
fn=run,
|
| 26 |
+
inputs=[image],
|
| 27 |
+
outputs=[output_text],
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
demo.launch(show_error=True)
|