Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from langchain_core.messages import HumanMessage, AIMessage
|
3 |
from llm import DeepSeekLLM, OpenRouterLLM, TongYiLLM
|
@@ -5,11 +7,8 @@ from config import settings
|
|
5 |
from modelscope.outputs import OutputKeys
|
6 |
from modelscope.pipelines import pipeline
|
7 |
from modelscope.utils.constant import Tasks
|
8 |
-
import cv2
|
9 |
-
from diffusers import StableDiffusionXLPipeline
|
10 |
-
import torch
|
11 |
from diffusers import (
|
12 |
-
|
13 |
DPMSolverMultistepScheduler,
|
14 |
DDIMScheduler,
|
15 |
HeunDiscreteScheduler,
|
@@ -71,14 +70,14 @@ def update_chat(_provider: str, _chat, _model: str, _temperature: float, _max_to
|
|
71 |
return _chat
|
72 |
|
73 |
|
74 |
-
def object_remove(_image,
|
75 |
mask = _image['layers'][0]
|
76 |
mask = mask.convert('L')
|
77 |
_input = {
|
78 |
'img': _image['background'].convert('RGB'),
|
79 |
'mask': mask,
|
80 |
}
|
81 |
-
inpainting = pipeline(Tasks.image_inpainting, model='damo/cv_fft_inpainting_lama', refined=
|
82 |
result = inpainting(_input)
|
83 |
vis_img = result[OutputKeys.OUTPUT_IMG]
|
84 |
vis_img = cv2.cvtColor(vis_img, cv2.COLOR_BGR2RGB)
|
@@ -119,6 +118,14 @@ def text_to_image(_prompt: str, _n_prompt: str, _scheduler: str, _inference_step
|
|
119 |
return result
|
120 |
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
with gr.Blocks() as app:
|
123 |
with gr.Tab('聊天'):
|
124 |
chat_engine = gr.State(value=None)
|
@@ -275,8 +282,12 @@ with gr.Blocks() as app:
|
|
275 |
with gr.Accordion(label="背景移除"):
|
276 |
bg_remove_type = gr.Radio(["人像", "通用"], label="类型", value='人像')
|
277 |
bg_remove_btn = gr.Button('背景移除', variant='primary')
|
|
|
|
|
|
|
278 |
object_remove_btn.click(fn=object_remove, inputs=[image, object_remove_refined], outputs=[image_preview, mask_preview])
|
279 |
bg_remove_btn.click(fn=bg_remove, inputs=[image, bg_remove_type], outputs=[image_preview])
|
|
|
280 |
|
281 |
with gr.Tab('画图(GPU)'):
|
282 |
with gr.Row():
|
|
|
1 |
+
import cv2
|
2 |
+
import torch
|
3 |
import gradio as gr
|
4 |
from langchain_core.messages import HumanMessage, AIMessage
|
5 |
from llm import DeepSeekLLM, OpenRouterLLM, TongYiLLM
|
|
|
7 |
from modelscope.outputs import OutputKeys
|
8 |
from modelscope.pipelines import pipeline
|
9 |
from modelscope.utils.constant import Tasks
|
|
|
|
|
|
|
10 |
from diffusers import (
|
11 |
+
StableDiffusionXLPipeline,
|
12 |
DPMSolverMultistepScheduler,
|
13 |
DDIMScheduler,
|
14 |
HeunDiscreteScheduler,
|
|
|
70 |
return _chat
|
71 |
|
72 |
|
73 |
+
def object_remove(_image, _refined: bool):
|
74 |
mask = _image['layers'][0]
|
75 |
mask = mask.convert('L')
|
76 |
_input = {
|
77 |
'img': _image['background'].convert('RGB'),
|
78 |
'mask': mask,
|
79 |
}
|
80 |
+
inpainting = pipeline(Tasks.image_inpainting, model='damo/cv_fft_inpainting_lama', refined=_refined)
|
81 |
result = inpainting(_input)
|
82 |
vis_img = result[OutputKeys.OUTPUT_IMG]
|
83 |
vis_img = cv2.cvtColor(vis_img, cv2.COLOR_BGR2RGB)
|
|
|
118 |
return result
|
119 |
|
120 |
|
121 |
+
def image_upscale(_image, _size: str):
|
122 |
+
sr = pipeline(Tasks.image_super_resolution, model='damo/cv_rrdb_image-super-resolution')
|
123 |
+
result = sr(_image['background'].convert('RGB'))
|
124 |
+
vis_img = result[OutputKeys.OUTPUT_IMG]
|
125 |
+
vis_img = cv2.cvtColor(vis_img, cv2.COLOR_BGR2RGB)
|
126 |
+
return vis_img
|
127 |
+
|
128 |
+
|
129 |
with gr.Blocks() as app:
|
130 |
with gr.Tab('聊天'):
|
131 |
chat_engine = gr.State(value=None)
|
|
|
282 |
with gr.Accordion(label="背景移除"):
|
283 |
bg_remove_type = gr.Radio(["人像", "通用"], label="类型", value='人像')
|
284 |
bg_remove_btn = gr.Button('背景移除', variant='primary')
|
285 |
+
with gr.Accordion(label="高清放大"):
|
286 |
+
upscale_size = gr.Radio(["X2", "X4"], label="放大倍数", value='X2')
|
287 |
+
upscale_btn = gr.Button('高清放大', variant='primary')
|
288 |
object_remove_btn.click(fn=object_remove, inputs=[image, object_remove_refined], outputs=[image_preview, mask_preview])
|
289 |
bg_remove_btn.click(fn=bg_remove, inputs=[image, bg_remove_type], outputs=[image_preview])
|
290 |
+
upscale_btn.click(fn=image_upscale, inputs=[image, upscale_size], outputs=[image_preview])
|
291 |
|
292 |
with gr.Tab('画图(GPU)'):
|
293 |
with gr.Row():
|