wsj1995 commited on
Commit
f96b34e
·
verified ·
1 Parent(s): c2bbcc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -66
app.py CHANGED
@@ -4,6 +4,7 @@ import oss2
4
  import os
5
  import gradio as gr
6
  import uuid
 
7
  import base64
8
  from io import BytesIO
9
  from oss2.credentials import EnvironmentVariableCredentialsProvider,StaticCredentialsProvider
@@ -54,8 +55,21 @@ def delete_local_file(file_path):
54
  print(f"{file_path} 文件不存在。")
55
 
56
 
57
- def run(url,version_id,access_key_id,access_key_secret,securityToken,endpoint,bucket_name,upload_filename,callback_url,callback_header_key,callback_header_secret):
58
-
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  # 网络图片 URL 和本地保存路径
60
  tmp_file_name = uuid.uuid4()
61
  result_image = f'{tmp_file_name}_compressed_image.jpg'
@@ -75,6 +89,8 @@ def run(url,version_id,access_key_id,access_key_secret,securityToken,endpoint,bu
75
  if oss_url:
76
  res = requests.post(callback_url,json={
77
  'version_id': version_id,
 
 
78
  },headers={
79
  f"{callback_header_key}": callback_header_secret
80
  })
@@ -96,63 +112,14 @@ with gr.Blocks() as demo:
96
 
97
  with gr.Column(elem_id="col-container"):
98
  with gr.Row():
99
- url = gr.Text(
100
  label="图片地址",
101
  show_label=False,
102
  max_lines=1,
103
  placeholder="input image url",
104
  container=False,
105
  )
106
- with gr.Row():
107
- version_id = gr.Textbox(
108
- label="AccessKeyId",
109
- placeholder="云存储 AccessKeyId",
110
- )
111
- with gr.Row():
112
- access_key_id = gr.Textbox(
113
- label="AccessKeyId",
114
- placeholder="云存储 AccessKeyId",
115
- )
116
- with gr.Row():
117
- access_key_secret = gr.Textbox(
118
- label="AccessKeySecret",
119
- placeholder="云存储 AccessKeySecret",
120
- )
121
- with gr.Row():
122
- securityToken = gr.Textbox(
123
- label="SecurityToken",
124
- placeholder="云存储 securityToken",
125
- )
126
- with gr.Row():
127
- endpoint = gr.Textbox(
128
- label="Endpoint",
129
- placeholder="云存储 endpoint",
130
- )
131
- with gr.Row():
132
- bucket_name = gr.Textbox(
133
- label="BucketName",
134
- placeholder="云存储 bucket_name",
135
- )
136
- with gr.Row():
137
- upload_filename = gr.Textbox(
138
- label="uploadFielName",
139
- placeholder="云存储 文件名称",
140
- )
141
- with gr.Row():
142
- callback_url = gr.Textbox(
143
- label="uploadFielName",
144
- placeholder="云存储 文件名称",
145
- )
146
- with gr.Row():
147
- callback_header_key = gr.Textbox(
148
- label="uploadFielName",
149
- placeholder="云存储 文件名称",
150
- )
151
- with gr.Row():
152
- callback_header_secret = gr.Textbox(
153
- label="uploadFielName",
154
- placeholder="云存储 文件名称",
155
- )
156
 
157
  with gr.Row():
158
  output = gr.Textbox(
@@ -168,19 +135,7 @@ with gr.Blocks() as demo:
168
  gr.on(
169
  triggers=[run_button.click],
170
  fn = run,
171
- inputs = [
172
- url,
173
- version_id,
174
- access_key_id,
175
- access_key_secret,
176
- securityToken,
177
- endpoint,
178
- bucket_name,
179
- upload_filename,
180
- callback_url,
181
- callback_header_key,
182
- callback_header_secret
183
- ],
184
  outputs = [output]
185
  )
186
 
 
4
  import os
5
  import gradio as gr
6
  import uuid
7
+ import json
8
  import base64
9
  from io import BytesIO
10
  from oss2.credentials import EnvironmentVariableCredentialsProvider,StaticCredentialsProvider
 
55
  print(f"{file_path} 文件不存在。")
56
 
57
 
58
+ def run(params):
59
+ params = json.loads(params)
60
+ url = params['url']
61
+ version_id = params['id']
62
+ access_key_id = params['access_key_id']
63
+ access_key_secret = params['access_key_secret']
64
+ securityToken = params['securityToken']
65
+ endpoint = params['endpoint']
66
+ bucket_name = params['bucket_name']
67
+ upload_filename = params['upload_filename']
68
+ callback_url = params['callback_url']
69
+ callback_header_key = params['callback_header_key']
70
+ callback_header_secret = params['callback_header_secret']
71
+ model_type = params['model_type']
72
+ # url,version_id,access_key_id,access_key_secret,securityToken,endpoint,bucket_name,upload_filename,callback_url,callback_header_key,callback_header_secret
73
  # 网络图片 URL 和本地保存路径
74
  tmp_file_name = uuid.uuid4()
75
  result_image = f'{tmp_file_name}_compressed_image.jpg'
 
89
  if oss_url:
90
  res = requests.post(callback_url,json={
91
  'version_id': version_id,
92
+ 'model_type': model_type,
93
+ 'filename': upload_filename
94
  },headers={
95
  f"{callback_header_key}": callback_header_secret
96
  })
 
112
 
113
  with gr.Column(elem_id="col-container"):
114
  with gr.Row():
115
+ params = gr.Text(
116
  label="图片地址",
117
  show_label=False,
118
  max_lines=1,
119
  placeholder="input image url",
120
  container=False,
121
  )
122
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  with gr.Row():
125
  output = gr.Textbox(
 
135
  gr.on(
136
  triggers=[run_button.click],
137
  fn = run,
138
+ inputs = [params],
 
 
 
 
 
 
 
 
 
 
 
 
139
  outputs = [output]
140
  )
141