rogerxavier commited on
Commit
0590c70
1 Parent(s): a507eeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -29
app.py CHANGED
@@ -7,6 +7,11 @@ import pandas as pd
7
  from PIL import Image
8
  from huggingface_hub import hf_hub_download
9
  from onnxruntime import InferenceSession
 
 
 
 
 
10
 
11
  # noinspection PyUnresolvedReferences
12
  def make_square(img, target_size):
@@ -175,32 +180,15 @@ def image_to_wd14_tags(image: Image.Image, model_name: str, threshold: float,
175
  return ratings, output_text, filtered_tags
176
 
177
 
178
- if __name__ == '__main__':
179
- with gr.Blocks(analytics_enabled=False, theme="NoCrypt/miku") as demo:
180
- with gr.Row():
181
- with gr.Column():
182
- gr_input_image = gr.Image(type='pil', label='Chen Chen', sources=['upload', 'clipboard'])
183
- with gr.Row():
184
- gr_model = gr.Radio(list(WAIFU_MODELS.keys()), value='chen-moat2', label='Chen')
185
- gr_threshold = gr.Slider(0.0, 1.0, 0.5, label='Chen Chen Chen Chen Chen')
186
- with gr.Row():
187
- gr_space = gr.Checkbox(value=True, label='Use DashSpace')
188
- gr_escape = gr.Checkbox(value=True, label='Chen Text Escape')
189
-
190
- gr_btn_submit = gr.Button(value='橙', variant='primary')
191
-
192
- with gr.Column():
193
- gr_ratings = gr.Label(label='橙 橙')
194
- with gr.Tabs():
195
- with gr.Tab("Chens"):
196
- gr_tags = gr.Label(label='Chens')
197
- with gr.Tab("Chen Text"):
198
- gr_output_text = gr.TextArea(label='Chen Text')
199
-
200
- gr_btn_submit.click(
201
- image_to_wd14_tags,
202
- inputs=[gr_input_image, 'chen-moat2', 0.5, True, True],
203
- outputs=[gr_ratings, gr_output_text, gr_tags],
204
- api_name="classify"
205
- )
206
- demo.queue(os.cpu_count()).launch()
 
7
  from PIL import Image
8
  from huggingface_hub import hf_hub_download
9
  from onnxruntime import InferenceSession
10
+ from fastapi import FastAPI, File, UploadFile,Body,Query,Response
11
+ import uvicorn
12
+ app = FastAPI()
13
+
14
+
15
 
16
  # noinspection PyUnresolvedReferences
17
  def make_square(img, target_size):
 
180
  return ratings, output_text, filtered_tags
181
 
182
 
183
+ #获取图片调用image_to_wd14_tags函数获取返回
184
+ @app.post("/getOriginalMangaList") #增加指定保存路径功能,默认是/manga路径
185
+ def getOriginalMangaList(image: UploadFile = File(...))->"ratings, output_text, filtered_tags":
186
+
187
+ img = image.file.read()
188
+ image_data = Image.open(io.BytesIO(img)).convert("L").convert("RGB")
189
+
190
+ return image_to_wd14_tags(image_data,'chen-moat2',0.5,True,True)
191
+
192
+
193
+ if __name__ == "__main__":
194
+ uvicorn.run(app, host="0.0.0.0", port=7860)