ascarlettvfx commited on
Commit
1491886
1 Parent(s): e7f42e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -41
app.py CHANGED
@@ -1,56 +1,31 @@
1
  import gradio as gr
2
- from gradio_client import Client, file
3
 
4
  def predict_depth(image):
5
- client = Client("prs-eth/marigold") # Adjust the username/modelname as needed
6
-
7
- # Assuming 'image' is the input image file from the user
8
- response = client.predict(
9
- file(image), # Image file path
10
- 1, # Ensemble size (example value)
11
- 10, # Number of denoising steps (example value)
12
- "0", # Processing resolution (example value)
13
- file('path_to_sample_file_1.pdf'), # Sample file path for depth (16-bit)
14
- file('path_to_sample_file_2.pdf'), # Sample file path for depth (32-bit)
15
- file('path_to_sample_file_3.pdf'), # Sample file path for depth (color)
16
- 0.5, # Relative position of the near plane
17
- 0.9, # Relative position of the far plane
18
- 10, # Embossing level
19
- 2, # Smoothing filter size
20
- -50, # Frame's near plane offset
21
  api_name="/submit_depth_fn"
22
  )
23
- # Assuming the API returns a filepath or you save the result to a file
24
- output_file_path = save_image_to_file(response['image']) # Implement this function based on your API's response
25
- return output_file_path
 
 
 
26
 
27
  # Gradio Interface
28
  iface = gr.Interface(
29
  fn=predict_depth,
30
  inputs=gr.Image(type='filepath', label="Upload your image"),
31
- outputs=gr.Image(type='filepath', label="Depth Map Image"),
32
  title="Depth Map Generator",
33
  description="Upload an image to receive a depth map file."
34
  )
35
 
36
  iface.launch()
37
-
38
- def save_image_to_file(image_data):
39
- # Assuming 'image_data' is the image data in a compatible format
40
- # You would save the image to a file and return the path
41
- import matplotlib.pyplot as plt
42
- import matplotlib.image as mpimg
43
- import numpy as np
44
- import tempfile
45
- import os
46
-
47
- # Create a temporary file
48
- fd, path = tempfile.mkstemp(suffix=".png")
49
- try:
50
- # Assume image_data is a numpy array
51
- img = np.array(image_data).astype(np.uint8)
52
- plt.imsave(path, img)
53
- finally:
54
- os.close(fd)
55
-
56
- return path
 
1
  import gradio as gr
2
+ from gradio_client import Client, handle_file
3
 
4
  def predict_depth(image):
5
+ client = Client("prs-eth/marigold")
6
+
7
+ # Prepare the API call with the necessary parameters
8
+ result = client.predict(
9
+ handle_file(image), # Image file path
10
+ 1, # Example value for 'Ensemble size'
11
+ 10, # Example value for 'Number of denoising steps'
12
+ "0", # Processing resolution choice
 
 
 
 
 
 
 
 
13
  api_name="/submit_depth_fn"
14
  )
15
+
16
+ # Process the API response assuming it directly returns a file path for the depth map
17
+ if result and result[0]: # Assuming the API returns the image path as the first item in a tuple
18
+ output_file_path = result[0] # Directly use the returned file path
19
+ return output_file_path # Return the path to the output file for download
20
+ return "No depth output available"
21
 
22
  # Gradio Interface
23
  iface = gr.Interface(
24
  fn=predict_depth,
25
  inputs=gr.Image(type='filepath', label="Upload your image"),
26
+ outputs=gr.File(label="Download Depth Map"),
27
  title="Depth Map Generator",
28
  description="Upload an image to receive a depth map file."
29
  )
30
 
31
  iface.launch()