Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
client = Client("https://fffiloni-moondream1.hf.space/")
|
6 |
result = client.predict(
|
7 |
image_in, # filepath in 'image' Image component
|
@@ -14,7 +37,7 @@ def infer(image_in, question):
|
|
14 |
with gr.Blocks() as demo:
|
15 |
with gr.Row():
|
16 |
with gr.Column():
|
17 |
-
|
18 |
question = gr.Textbox()
|
19 |
submit_btn = gr.Button("Submit")
|
20 |
with gr.Column():
|
@@ -22,7 +45,7 @@ with gr.Blocks() as demo:
|
|
22 |
|
23 |
submit_btn.click(
|
24 |
fn=infer,
|
25 |
-
inputs=[
|
26 |
outputs=[answer]
|
27 |
)
|
28 |
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
import base64
|
7 |
+
|
8 |
+
def convert_base64_to_img(image_string):
|
9 |
+
# Split the input string to separate the metadata header and the base64-encoded data
|
10 |
+
header, encoded_data = image_string.split(",", 1)
|
11 |
+
|
12 |
+
# Now, encoded_data contains the base64-encoded image data
|
13 |
+
image_data = base64.b64decode(encoded_data)
|
14 |
+
|
15 |
+
# Create a BytesIO object to store the image data
|
16 |
+
image_file = io.BytesIO(image_data)
|
17 |
+
|
18 |
+
# Open the image using the BytesIO object
|
19 |
+
img = Image.open(image_file)
|
20 |
+
|
21 |
+
# Save the image as a JPEG file
|
22 |
+
img.save('output.png', 'PNG')
|
23 |
+
|
24 |
+
return "output.png"
|
25 |
+
|
26 |
+
def infer(image_string, question):
|
27 |
+
image_in = convert_base64_to_img(image_string)
|
28 |
client = Client("https://fffiloni-moondream1.hf.space/")
|
29 |
result = client.predict(
|
30 |
image_in, # filepath in 'image' Image component
|
|
|
37 |
with gr.Blocks() as demo:
|
38 |
with gr.Row():
|
39 |
with gr.Column():
|
40 |
+
image_string = gr.Textbox()
|
41 |
question = gr.Textbox()
|
42 |
submit_btn = gr.Button("Submit")
|
43 |
with gr.Column():
|
|
|
45 |
|
46 |
submit_btn.click(
|
47 |
fn=infer,
|
48 |
+
inputs=[image_string, question],
|
49 |
outputs=[answer]
|
50 |
)
|
51 |
|