Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
import torch
|
4 |
from langs import LANGS
|
5 |
-
import os
|
6 |
|
7 |
import numpy as np
|
8 |
import modin.pandas as pd
|
@@ -14,7 +13,7 @@ device1 = "cuda" if torch.cuda.is_available() else "cpu"
|
|
14 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", safety_checker=None)
|
15 |
pipe = pipe.to(device1)
|
16 |
|
17 |
-
pipe1 = pipeline('text-generation', model='
|
18 |
|
19 |
TASK = "translation"
|
20 |
CKPT = "facebook/nllb-200-distilled-600M"
|
@@ -46,23 +45,8 @@ def translate(text):
|
|
46 |
|
47 |
#prompt
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
def get_images(prompt):
|
53 |
-
gallery_dir = stable_diffusion(prompt, fn_index=2)
|
54 |
-
img_results = [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)]
|
55 |
-
return img_results[0]
|
56 |
-
|
57 |
-
def get_new_prompt(img, mode):
|
58 |
-
interrogate = clip_interrogator_2(img, mode, 12, api_name="clipi2")
|
59 |
-
return interrogate
|
60 |
-
|
61 |
-
def infer(input):
|
62 |
-
prompt = pipe1(input+',', num_return_sequences=1)[0]["generated_text"]
|
63 |
-
img = get_images(prompt)
|
64 |
-
result = get_new_prompt(img, 'fast')
|
65 |
-
return result[0]
|
66 |
|
67 |
#stable diffusion
|
68 |
|
@@ -93,7 +77,7 @@ with gr.Blocks() as demo:
|
|
93 |
btn1 = gr.Button("让您的提示词更详细一些吧")
|
94 |
out2 = gr.Textbox(label = "更详细的英文提示词(可编辑此内容)", lines=1)
|
95 |
|
96 |
-
btn1.click(
|
97 |
|
98 |
with gr.Row().style(equal_height=True):
|
99 |
inp3 = out2
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
import torch
|
4 |
from langs import LANGS
|
|
|
5 |
|
6 |
import numpy as np
|
7 |
import modin.pandas as pd
|
|
|
13 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", safety_checker=None)
|
14 |
pipe = pipe.to(device1)
|
15 |
|
16 |
+
pipe1 = pipeline('text-generation', model='daspartho/prompt-extend')
|
17 |
|
18 |
TASK = "translation"
|
19 |
CKPT = "facebook/nllb-200-distilled-600M"
|
|
|
45 |
|
46 |
#prompt
|
47 |
|
48 |
+
def extend_prompt(prompt):
|
49 |
+
return pipe1(prompt+',', num_return_sequences=1)[0]["generated_text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
#stable diffusion
|
52 |
|
|
|
77 |
btn1 = gr.Button("让您的提示词更详细一些吧")
|
78 |
out2 = gr.Textbox(label = "更详细的英文提示词(可编辑此内容)", lines=1)
|
79 |
|
80 |
+
btn1.click(extend_prompt, [inp2], [out2])
|
81 |
|
82 |
with gr.Row().style(equal_height=True):
|
83 |
inp3 = out2
|