Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,6 @@ import json
|
|
4 |
import io
|
5 |
import random
|
6 |
import os
|
7 |
-
import torch
|
8 |
-
from transformers import pipeline
|
9 |
from PIL import Image
|
10 |
|
11 |
API_BASE_URL = "https://api-inference.huggingface.co/models/"
|
@@ -30,24 +28,10 @@ MODEL_LIST = [
|
|
30 |
API_TOKEN = os.getenv("HF_READ_TOKEN") # Make sure to set your Hugging Face token
|
31 |
HEADERS = {"Authorization": f"Bearer {API_TOKEN}"}
|
32 |
|
33 |
-
pipe = pipeline("text-generation", model="isek-ai/SDPrompt-RetNet-300M", trust_remote_code=True)
|
34 |
-
|
35 |
def select_model(model_name):
|
36 |
if model_name in MODEL_LIST:
|
37 |
return f"{API_BASE_URL}{model_name}"
|
38 |
|
39 |
-
def extend_prompt(input_text):
|
40 |
-
if not input_text.strip():
|
41 |
-
gr.Warning("Input text is empty!")
|
42 |
-
return None
|
43 |
-
|
44 |
-
seed = random.randint(1, 1000000)
|
45 |
-
torch.manual_seed(seed)
|
46 |
-
|
47 |
-
output = pipe(input_text, max_length=(len(input_text) + random.randint(60, 90)), num_return_sequences=4)
|
48 |
-
|
49 |
-
return output
|
50 |
-
|
51 |
def generate_image(prompt, selected_model, is_negative=False, steps=1, cfg_scale=6, seed=None):
|
52 |
if not prompt.strip():
|
53 |
raise gr.Error("Cannot generate image: Input text is empty!")
|
@@ -94,12 +78,10 @@ with gr.Blocks(theme="soft") as playground:
|
|
94 |
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
|
95 |
model_dropdown = gr.Dropdown(label="Model", choices=MODEL_LIST, elem_id="model-dropdown", value="runwayml/stable-diffusion-v1-5")
|
96 |
gen_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
|
97 |
-
extend_button = gr.Button("Extend Prompt", variant='primary', elem_id="extend-button")
|
98 |
|
99 |
with gr.Accordion("Advanced settings", open=False):
|
100 |
negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
|
101 |
|
102 |
gen_button.click(generate_image, inputs=[text_prompt, model_dropdown, negative_prompt], outputs=image_output)
|
103 |
-
|
104 |
-
|
105 |
playground.launch(show_api=False)
|
|
|
4 |
import io
|
5 |
import random
|
6 |
import os
|
|
|
|
|
7 |
from PIL import Image
|
8 |
|
9 |
API_BASE_URL = "https://api-inference.huggingface.co/models/"
|
|
|
28 |
API_TOKEN = os.getenv("HF_READ_TOKEN") # Make sure to set your Hugging Face token
|
29 |
HEADERS = {"Authorization": f"Bearer {API_TOKEN}"}
|
30 |
|
|
|
|
|
31 |
def select_model(model_name):
|
32 |
if model_name in MODEL_LIST:
|
33 |
return f"{API_BASE_URL}{model_name}"
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
def generate_image(prompt, selected_model, is_negative=False, steps=1, cfg_scale=6, seed=None):
|
36 |
if not prompt.strip():
|
37 |
raise gr.Error("Cannot generate image: Input text is empty!")
|
|
|
78 |
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
|
79 |
model_dropdown = gr.Dropdown(label="Model", choices=MODEL_LIST, elem_id="model-dropdown", value="runwayml/stable-diffusion-v1-5")
|
80 |
gen_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
|
|
|
81 |
|
82 |
with gr.Accordion("Advanced settings", open=False):
|
83 |
negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
|
84 |
|
85 |
gen_button.click(generate_image, inputs=[text_prompt, model_dropdown, negative_prompt], outputs=image_output)
|
86 |
+
|
|
|
87 |
playground.launch(show_api=False)
|