wrl2003 commited on
Commit
e5fdb98
·
1 Parent(s): 6131659

Update space

Browse files
Files changed (1) hide show
  1. app.py +68 -16
app.py CHANGED
@@ -1,18 +1,70 @@
1
  import gradio as gr
 
 
 
 
 
 
 
2
 
3
- def add_numbers(num1, num2):
4
- # 这个函数接收两个参数并返回它们的和。
5
- return num1 + num2
6
-
7
- # 创建Gradio的界面
8
- demo = gr.Interface(
9
- fn=add_numbers, # 指定用于计算的函数
10
- inputs=[gr.Number(label="第一个数"), gr.Number(label="第二个数")], # 输入组件,这里是两个数字输入框
11
- outputs=gr.Number(label="两数之和"), # 输出组件,这里是一个数字输出框
12
- title="简单加法器", # 界面标题
13
- description="输入两个数字,点击提交按钮以查看它们的和。" # 界面描述
14
- )
15
-
16
- # 启动应用
17
- if __name__ == "__main__":
18
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ import os
5
+ from PIL import Image
6
+ import spaces
7
+ import torch
8
+ from gradio_imageslider import ImageSlider
9
 
10
+ css = """
11
+ #img-display-container {
12
+ max-height: 100vh;
13
+ }
14
+ #img-display-input {
15
+ max-height: 80vh;
16
+ }
17
+ #img-display-output {
18
+ max-height: 80vh;
19
+ }
20
+ """
21
+ DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
22
+ title = "# Stereo Anything"
23
+ description = """Official demo for **Stereo Anything: Unifying Stereo Matching with Large-Scale Mixed Data**.
24
+ Please refer to our [paper](https://arxiv.org/abs/2411.14053), [github](https://github.com/XiandaGuo/OpenStereo/) for more details."""
25
+
26
+ @spaces.GPU
27
+ @torch.no_grad()
28
+ def predict_depth(model, image):
29
+ return model(image)
30
+
31
+
32
+ with gr.Blocks(css=css) as demo:
33
+ gr.Markdown(title)
34
+ gr.Markdown(description)
35
+ gr.Markdown("### Depth Prediction demo")
36
+ gr.Markdown("You can slide the output to compare the depth prediction with input image")
37
+
38
+ with gr.Row():
39
+ left_image = gr.Image(label="Left Image", type='numpy', elem_id='img-display-input')
40
+ right_image = gr.Image(label="Right Image", type='numpy', elem_id='img-display-input')
41
+ depth_image_slider = ImageSlider(label="Depth Map with Slider View", elem_id='img-display-output', position=0.5,)
42
+ # raw_file = gr.File(label="16-bit raw depth (can be considered as disparity)")
43
+ submit = gr.Button("Submit")
44
+
45
+ def on_submit(left_image,right_image):
46
+ sample = {
47
+ 'left': left_image,
48
+ 'right': right_image,
49
+ }
50
+ sample['left'] = sample['left'].unsqueeze(0)
51
+ sample['right'] = sample['right'].unsqueeze(0)
52
+
53
+ model.eval()
54
+ for k, v in sample.items():
55
+ sample[k] = v.to(0) if torch.is_tensor(v) else v
56
+
57
+ model_pred = model(sample)
58
+
59
+ return [model_pred]
60
+
61
+ submit.click(on_submit, inputs=[left_image,right_image], outputs=[depth_image_slider])
62
+
63
+ example_files = os.listdir('examples')
64
+ example_files.sort()
65
+ example_files = [os.path.join('examples', filename) for filename in example_files]
66
+ examples = gr.Examples(examples=example_files, inputs=[left_image,right_image], outputs=[depth_image_slider], fn=on_submit, cache_examples=True)
67
+
68
+
69
+ if __name__ == '__main__':
70
+ demo.queue().launch()