Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,7 @@
|
|
1 |
-
from run import process
|
2 |
-
import time
|
3 |
-
import subprocess
|
4 |
-
import os
|
5 |
-
import argparse
|
6 |
-
import cv2
|
7 |
-
import sys
|
8 |
-
from PIL import Image
|
9 |
-
import torch
|
10 |
import gradio as gr
|
|
|
|
|
|
|
11 |
|
12 |
TESTdevice = "cpu"
|
13 |
index = 1
|
@@ -39,39 +33,46 @@ def inference(img):
|
|
39 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
40 |
return output
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
]
|
|
|
49 |
|
50 |
-
css =
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
.
|
57 |
-
background-color: rgb(17, 24, 39) !important;
|
58 |
-
border: none !important;
|
59 |
-
max-width: 100%; /* Ensure it does not exceed the container's width */
|
60 |
-
max-height: 100%; /* Ensure it does not exceed the container's height */
|
61 |
-
overflow: hidden; /* Prevent internal scrolling */
|
62 |
-
}
|
63 |
-
footer {display: none !important;} /* Hide footer */
|
64 |
-
"""
|
65 |
|
66 |
-
|
67 |
-
with gr.Column():
|
68 |
-
image_input = gr.Image(type="numpy", label="Upload Image", height=512, width=512)
|
69 |
-
process_button = gr.Button("Process Image")
|
70 |
-
status = gr.Markdown(value="")
|
71 |
|
72 |
-
|
73 |
-
return inference(img), gr.update(value="Processing complete!")
|
74 |
|
75 |
-
|
76 |
|
77 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import time
|
4 |
+
from urllib.parse import parse_qs, urlparse
|
5 |
|
6 |
TESTdevice = "cpu"
|
7 |
index = 1
|
|
|
33 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
34 |
return output
|
35 |
|
36 |
+
def get_css(bg_color, width, height):
|
37 |
+
return f"""
|
38 |
+
body {{
|
39 |
+
background-color: {bg_color};
|
40 |
+
color: white;
|
41 |
+
overflow: hidden; /* Prevent scrolling */
|
42 |
+
}}
|
43 |
+
.gradio-container {{
|
44 |
+
background-color: {bg_color} !important;
|
45 |
+
border: none !important;
|
46 |
+
width: {width} !important; /* Set the width */
|
47 |
+
height: {height} !important; /* Set the height */
|
48 |
+
max-width: 100%; /* Ensure it does not exceed the container's width */
|
49 |
+
max-height: 100%; /* Ensure it does not exceed the container's height */
|
50 |
+
overflow: scroll; /* Prevent internal scrolling */
|
51 |
+
}}
|
52 |
+
footer {{display: none !important;}} /* Hide footer */
|
53 |
+
"""
|
54 |
+
|
55 |
+
def update_status(img):
|
56 |
+
return inference(img), gr.update(value="Processing complete!")
|
57 |
|
58 |
+
def create_interface(request):
|
59 |
+
query_params = parse_qs(urlparse(request.url).query)
|
60 |
+
bg_color = query_params.get('bg_color', ['rgb(17, 24, 39)'])[0]
|
61 |
+
width = int(query_params.get('width', ['auto'])[0])
|
62 |
+
height = int(query_params.get('height', ['100%'])[0])
|
63 |
|
64 |
+
css = get_css(bg_color, width, height)
|
65 |
+
|
66 |
+
with gr.Blocks(css=css) as demo:
|
67 |
+
with gr.Column():
|
68 |
+
image_input = gr.Image(type="numpy", label="Upload Image", height=height, width=width)
|
69 |
+
process_button = gr.Button("Process Image")
|
70 |
+
status = gr.Markdown(value="")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
process_button.click(update_status, inputs=image_input, outputs=[image_input, status])
|
|
|
|
|
|
|
|
|
73 |
|
74 |
+
return demo
|
|
|
75 |
|
76 |
+
demo = gr.Interface(create_interface, inputs=[], outputs=[])
|
77 |
|
78 |
demo.launch()
|