nsfwalex commited on
Commit
f0978c5
โ€ข
1 Parent(s): d948530

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -43,11 +43,11 @@ def get_css(bg_color, width, height):
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
  """
@@ -55,24 +55,32 @@ def get_css(bg_color, width, height):
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()
 
43
  .gradio-container {{
44
  background-color: {bg_color} !important;
45
  border: none !important;
46
+ width: {width}px !important; /* Set the width */
47
+ height: {height}px !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: hidden; /* Prevent internal scrolling */
51
  }}
52
  footer {{display: none !important;}} /* Hide footer */
53
  """
 
55
  def update_status(img):
56
  return inference(img), gr.update(value="Processing complete!")
57
 
58
+ def create_interface():
59
+ # Default values
60
+ bg_color = 'rgb(17, 24, 39)'
61
+ width = 'auto'
62
+ height = '100%'
63
 
64
+ # Function to update the interface based on the URL parameters
65
+ def update_interface(request: gr.Request):
66
+ nonlocal bg_color, width, height
67
+ query_params = parse_qs(urlparse(request.url).query)
68
+ bg_color = query_params.get('bg_color', [bg_color])[0]
69
+ width = int(query_params.get('width', [width])[0])
70
+ height = int(query_params.get('height', [height])[0])
71
+ css = get_css(bg_color, width, height)
72
+ return gr.Blocks(css=css)
73
 
74
+ with gr.Blocks() as demo:
75
+ gr.Markdown("Loading...") # Temporary placeholder
76
+
77
+ demo.load(update_interface)
78
 
79
  return demo
80
 
81
+ demo = create_interface()
82
+
83
+ with gr.Blocks() as outer_demo:
84
+ outer_demo.mount(demo)
85
 
86
  demo.launch()