leaf1170124460 commited on
Commit
54abd3b
·
1 Parent(s): 0a17a2b

F-upload codes

Browse files
Files changed (2) hide show
  1. .gitignore +2 -0
  2. app.py +73 -7
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .history/
2
+ .history
app.py CHANGED
@@ -1,14 +1,80 @@
1
  import os
2
  import gradio as gr
 
3
 
4
  HF_TOKEN = os.environ.get('HF_KEY')
5
- demo = gr.load('leaf1170124460/mattingPrivate', src='spaces', hf_token=HF_TOKEN)
6
 
7
- if __name__ == '__main__':
8
- demo.queue(
9
- api_open=False,
10
- ).launch(
11
- server_name="0.0.0.0",
12
- server_port=7860,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  )
14
 
 
 
 
 
 
 
 
 
1
  import os
2
  import gradio as gr
3
+ from gradio_client import Client, handle_file
4
 
5
  HF_TOKEN = os.environ.get('HF_KEY')
 
6
 
7
+ client = Client("leaf1170124460/mattingPrivate", hf_token=HF_TOKEN)
8
+
9
+ def process_image_check(path_input):
10
+ if path_input is None:
11
+ raise gr.Error(
12
+ "Missing image in the left pane: please upload an image first."
13
+ )
14
+
15
+ def process_pipe_matting(matting_image_input):
16
+ return client.predict(
17
+ path_input=handle_file(matting_image_input),
18
+ api_name="/gradio_handler"
19
+ )
20
+
21
+ def run_demo_server():
22
+ gradio_theme = gr.themes.Default()
23
+ with gr.Blocks(
24
+ theme=gradio_theme,
25
+ title="Matting",
26
+ ) as demo:
27
+ with gr.Row():
28
+ gr.Markdown("# Matting Demo")
29
+ with gr.Row():
30
+ gr.Markdown("### Due to the GPU quota limit, if an error occurs, please wait for 1 minute before retrying.")
31
+ with gr.Row():
32
+ with gr.Column():
33
+ matting_image_input = gr.Image(
34
+ label="Input Image",
35
+ type="filepath",
36
+ )
37
+ with gr.Row():
38
+ matting_image_submit_btn = gr.Button(
39
+ value="Estimate Matting", variant="primary"
40
+ )
41
+ matting_image_reset_btn = gr.Button(value="Reset")
42
+ with gr.Column():
43
+ matting_image_output = gr.Image(label='Output')
44
+
45
+
46
+ matting_image_submit_btn.click(
47
+ fn=process_image_check,
48
+ inputs=matting_image_input,
49
+ outputs=None,
50
+ preprocess=False,
51
+ queue=False,
52
+ ).success(
53
+ fn=process_pipe_matting,
54
+ inputs=[
55
+ matting_image_input,
56
+ ],
57
+ outputs=[matting_image_output],
58
+ concurrency_limit=1,
59
+ )
60
+
61
+ matting_image_reset_btn.click(
62
+ fn=lambda: (
63
+ None,
64
+ None,
65
+ ),
66
+ inputs=[],
67
+ outputs=[
68
+ matting_image_input,
69
+ matting_image_output,
70
+ ],
71
+ queue=False,
72
  )
73
 
74
+ demo.queue(
75
+ api_open=False,
76
+ ).launch()
77
+
78
+
79
+ if __name__ == '__main__':
80
+ run_demo_server()