sahadev10 commited on
Commit
0b4b741
·
verified ·
1 Parent(s): 3619fee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -125,7 +125,6 @@
125
 
126
 
127
 
128
-
129
  import torch
130
  import numpy as np
131
  import cv2
@@ -156,7 +155,7 @@ cfg.MODEL.DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
156
  predictor = DefaultPredictor(cfg)
157
 
158
  # Replace with your actual Ngrok or backend URL
159
- NGROK_URL = " https://9dbc-210-212-162-140.ngrok-free.app/upload" # Change this
160
 
161
  def process_image(image, user_height_cm):
162
  # Convert Gradio image input to OpenCV format
@@ -260,7 +259,7 @@ def save_to_database(measurements, image, user_height_cm):
260
 
261
  # Send POST request
262
  response = requests.post(
263
- "https://your-ngrok-url.ngrok.io/measurements", # Change this
264
  json={
265
  "imageBase64": img_str,
266
  "heightCm": user_height_cm,
@@ -275,22 +274,27 @@ def save_to_database(measurements, image, user_height_cm):
275
  return f"Status: {response.status_code}, Message: {response.text}"
276
 
277
  # Gradio Interface
278
- demo = gr.Interface(
279
- fn=process_image,
280
- inputs=[gr.Image(type="pil"), gr.Number(label="User Height (cm)")],
281
- outputs=[gr.JSON(label="Measurements"), gr.Image(type="pil", label="Keypoint Overlay")],
282
- title="Keypoint Measurement Extractor",
283
- description="Upload an image, enter your height, and get body measurements based on keypoints.",
284
- )
285
-
286
- # Add Save to Database button functionality
287
- save_btn = gr.Button("Save to Database")
288
- save_status = gr.Textbox(label="Save Status", interactive=False)
289
-
290
- save_btn.click(
291
- fn=save_to_database,
292
- inputs=[demo.outputs[0], demo.outputs[1], gr.Number(label="User Height (cm)")],
293
- outputs=save_status
294
- )
295
-
 
 
 
 
 
296
  demo.launch()
 
125
 
126
 
127
 
 
128
  import torch
129
  import numpy as np
130
  import cv2
 
155
  predictor = DefaultPredictor(cfg)
156
 
157
  # Replace with your actual Ngrok or backend URL
158
+ NGROK_URL = "https://your-ngrok-url.ngrok.io/measurements" # Change this
159
 
160
  def process_image(image, user_height_cm):
161
  # Convert Gradio image input to OpenCV format
 
259
 
260
  # Send POST request
261
  response = requests.post(
262
+ "https://9dbc-210-212-162-140.ngrok-free.app/upload", # Change this
263
  json={
264
  "imageBase64": img_str,
265
  "heightCm": user_height_cm,
 
274
  return f"Status: {response.status_code}, Message: {response.text}"
275
 
276
  # Gradio Interface
277
+ def create_interface():
278
+ with gr.Blocks() as demo:
279
+ with gr.Row():
280
+ img_input = gr.Image(type="pil", label="Upload Image")
281
+ height_input = gr.Number(label="User Height (cm)")
282
+
283
+ with gr.Row():
284
+ output_measurements = gr.JSON(label="Measurements")
285
+ output_image = gr.Image(type="pil", label="Keypoint Overlay")
286
+
287
+ save_btn = gr.Button("Save to Database")
288
+ save_status = gr.Textbox(label="Save Status", interactive=False)
289
+
290
+ img_input.change(fn=process_image, inputs=[img_input, height_input], outputs=[output_measurements, output_image])
291
+ save_btn.click(
292
+ fn=save_to_database,
293
+ inputs=[output_measurements, output_image, height_input],
294
+ outputs=save_status
295
+ )
296
+
297
+ return demo
298
+
299
+ demo = create_interface()
300
  demo.launch()