Spaces:
Runtime error
Runtime error
restful
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import io
|
@@ -7,6 +8,7 @@ from scripts.process_utils import initialize, process_image_as_base64
|
|
7 |
from scripts.anime import init_model
|
8 |
from scripts.generate_prompt import load_wd14_tagger_model
|
9 |
|
|
|
10 |
# 初期化
|
11 |
initialize(_use_local=False, use_gpu=True, use_dotenv=False)
|
12 |
init_model(use_local=False)
|
@@ -17,13 +19,8 @@ def process_image(input_image, mode, weight1, weight2):
|
|
17 |
sotai_image, sketch_image = process_image_as_base64(input_image, mode, weight1, weight2)
|
18 |
return sotai_image, sketch_image
|
19 |
|
20 |
-
def gradio_process_image(input_image, mode, weight1, weight2):
|
21 |
-
|
22 |
-
input_image_bytes = io.BytesIO()
|
23 |
-
input_image.save(input_image_bytes, format='PNG')
|
24 |
-
input_image_base64 = base64.b64encode(input_image_bytes.getvalue()).decode('utf-8')
|
25 |
-
|
26 |
-
sotai_base64, sketch_base64 = process_image(input_image_base64, mode, weight1, weight2)
|
27 |
return sotai_base64, sketch_base64
|
28 |
|
29 |
# Gradio インターフェースの定義
|
@@ -43,8 +40,8 @@ iface = gr.Interface(
|
|
43 |
description="Upload an image and select processing options to generate body and sketch images."
|
44 |
)
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
|
49 |
# Hugging Face Spacesでデプロイする場合
|
50 |
iface.queue().launch()
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
import io
|
|
|
8 |
from scripts.anime import init_model
|
9 |
from scripts.generate_prompt import load_wd14_tagger_model
|
10 |
|
11 |
+
app = FastAPI()
|
12 |
# 初期化
|
13 |
initialize(_use_local=False, use_gpu=True, use_dotenv=False)
|
14 |
init_model(use_local=False)
|
|
|
19 |
sotai_image, sketch_image = process_image_as_base64(input_image, mode, weight1, weight2)
|
20 |
return sotai_image, sketch_image
|
21 |
|
22 |
+
def gradio_process_image(input_image, mode, weight1, weight2):
|
23 |
+
sotai_base64, sketch_base64 = process_image(input_image, mode, weight1, weight2)
|
|
|
|
|
|
|
|
|
|
|
24 |
return sotai_base64, sketch_base64
|
25 |
|
26 |
# Gradio インターフェースの定義
|
|
|
40 |
description="Upload an image and select processing options to generate body and sketch images."
|
41 |
)
|
42 |
|
43 |
+
# APIとして公開
|
44 |
+
app = gr.mount_gradio_app(app, iface, path="/")
|
45 |
|
46 |
# Hugging Face Spacesでデプロイする場合
|
47 |
iface.queue().launch()
|