Spaces:
Build error
Build error
Doubleupai
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,48 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
from PIL import Image
|
4 |
-
import
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
img_byte_arr = img_byte_arr.getvalue()
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return output_image
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
)
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
from PIL import Image
|
5 |
+
import torch
|
6 |
|
7 |
+
# Загрузка модели Qwen/QVQ-72B-preview (пример для текстовой модели)
|
8 |
+
def load_text_model():
|
9 |
+
text_pipeline = pipeline("text-generation", model="Qwen/QVQ-72B-preview")
|
10 |
+
return text_pipeline
|
|
|
11 |
|
12 |
+
# Загрузка модели fffiloni/AniDoc (пример для модели анализа изображений)
|
13 |
+
def load_image_model():
|
14 |
+
image_pipeline = StableDiffusionPipeline.from_pretrained("fffiloni/AniDoc")
|
15 |
+
return image_pipeline
|
16 |
|
17 |
+
# Функция для генерации текста
|
18 |
+
def generate_text(prompt, text_pipeline):
|
19 |
+
result = text_pipeline(prompt, max_length=50)
|
20 |
+
return result[0]['generated_text']
|
21 |
+
|
22 |
+
# Функция для анализа изображения
|
23 |
+
def analyze_image(image, image_pipeline):
|
24 |
+
# Пример: генерация изображения на основе входного изображения
|
25 |
+
prompt = "Anime style"
|
26 |
+
output_image = image_pipeline(prompt, image=image).images[0]
|
27 |
return output_image
|
28 |
|
29 |
+
# Загрузка моделей
|
30 |
+
text_pipeline = load_text_model()
|
31 |
+
image_pipeline = load_image_model()
|
32 |
+
|
33 |
+
# Создание Gradio интерфейса
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
with gr.Tab("Text Generation"):
|
36 |
+
text_input = gr.Textbox(label="Input Prompt")
|
37 |
+
text_output = gr.Textbox(label="Generated Text")
|
38 |
+
text_button = gr.Button("Generate Text")
|
39 |
+
text_button.click(fn=generate_text, inputs=[text_input, gr.State(text_pipeline)], outputs=text_output)
|
40 |
+
|
41 |
+
with gr.Tab("Image Analysis"):
|
42 |
+
image_input = gr.Image(label="Input Image", type="pil")
|
43 |
+
image_output = gr.Image(label="Output Image")
|
44 |
+
image_button = gr.Button("Analyze Image")
|
45 |
+
image_button.click(fn=analyze_image, inputs=[image_input, gr.State(image_pipeline)], outputs=image_output)
|
46 |
+
|
47 |
+
# Запуск интерфейса
|
48 |
+
demo.launch()
|