Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
|
|
|
| 3 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 4 |
|
| 5 |
def load_model(model_path, dtype):
|
|
@@ -42,6 +43,7 @@ def generate(
|
|
| 42 |
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
|
| 43 |
|
| 44 |
if seed_checkbox:
|
|
|
|
| 45 |
torch.manual_seed(seed)
|
| 46 |
|
| 47 |
outputs = model.generate(
|
|
@@ -107,6 +109,7 @@ additional_inputs = [
|
|
| 107 |
value=False,
|
| 108 |
label="Use Random Seed",
|
| 109 |
info="Check to use a random seed for the generation process",
|
|
|
|
| 110 |
),
|
| 111 |
gr.Number(
|
| 112 |
value=42,
|
|
@@ -122,6 +125,13 @@ additional_inputs = [
|
|
| 122 |
),
|
| 123 |
]
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
examples = [
|
| 126 |
[
|
| 127 |
"Expand the following prompt to add more detail: A storefront with 'Text to Image' written on it.",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
import random
|
| 4 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 5 |
|
| 6 |
def load_model(model_path, dtype):
|
|
|
|
| 43 |
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
|
| 44 |
|
| 45 |
if seed_checkbox:
|
| 46 |
+
seed = random.randint(1, 100000)
|
| 47 |
torch.manual_seed(seed)
|
| 48 |
|
| 49 |
outputs = model.generate(
|
|
|
|
| 109 |
value=False,
|
| 110 |
label="Use Random Seed",
|
| 111 |
info="Check to use a random seed for the generation process",
|
| 112 |
+
change=update_ui,
|
| 113 |
),
|
| 114 |
gr.Number(
|
| 115 |
value=42,
|
|
|
|
| 125 |
),
|
| 126 |
]
|
| 127 |
|
| 128 |
+
def update_ui(seed_checkbox):
|
| 129 |
+
if seed_checkbox:
|
| 130 |
+
return gr.Number.update(visible=False)
|
| 131 |
+
else:
|
| 132 |
+
return gr.Number.update(visible=True)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
examples = [
|
| 136 |
[
|
| 137 |
"Expand the following prompt to add more detail: A storefront with 'Text to Image' written on it.",
|