Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,186 +4,359 @@ import imageio
|
|
| 4 |
import torch
|
| 5 |
import time
|
| 6 |
import os
|
| 7 |
-
|
| 8 |
-
from transformers import pipeline
|
|
|
|
| 9 |
from diffusers import DiffusionPipeline
|
| 10 |
|
| 11 |
-
# ---------- Load OpenAI Key from Hugging Face Secret ----------
|
| 12 |
-
client = OpenAI(api_key=os.getenv("OPENAI_KEY"))
|
| 13 |
|
| 14 |
-
# ----------
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"GPT-2 (small, fast)": "gpt2",
|
| 18 |
-
"Falcon (TII UAE)": "tiiuae/falcon-7b-instruct",
|
| 19 |
-
"Mistral (OpenAccess)": "mistralai/Mistral-7B-v0.1"
|
| 20 |
-
}
|
| 21 |
|
| 22 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 23 |
text_model_cache = {}
|
| 24 |
chat_memory = {}
|
| 25 |
-
last_usage_time = {}
|
| 26 |
|
| 27 |
-
MAX_PROMPTS_PER_SESSION = 5
|
| 28 |
-
THROTTLE_SECONDS = 30
|
| 29 |
|
| 30 |
-
# ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
try:
|
|
|
|
| 32 |
image_generator = DiffusionPipeline.from_pretrained(
|
| 33 |
-
"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
)
|
|
|
|
| 37 |
image_generator.to(device)
|
|
|
|
| 38 |
image_enabled = True
|
|
|
|
| 39 |
except Exception as e:
|
|
|
|
| 40 |
print(f"[Image Model Load Error]: {e}")
|
| 41 |
image_generator = None
|
| 42 |
image_enabled = False
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
try:
|
|
|
|
| 46 |
video_pipeline = DiffusionPipeline.from_pretrained(
|
| 47 |
-
"
|
| 48 |
-
safety_checker=None,
|
| 49 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
| 50 |
)
|
|
|
|
| 51 |
video_pipeline.to(device)
|
|
|
|
| 52 |
video_enabled = True
|
|
|
|
| 53 |
except Exception as e:
|
|
|
|
| 54 |
print(f"[Video Model Load Error]: {e}")
|
| 55 |
video_pipeline = None
|
| 56 |
video_enabled = False
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
if session_id not in chat_memory:
|
| 62 |
chat_memory[session_id] = []
|
| 63 |
|
| 64 |
if prompt.lower() in ["exit", "quit"]:
|
| 65 |
chat_memory[session_id] = []
|
| 66 |
-
yield "🧠 Codette
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
return
|
| 68 |
|
| 69 |
-
if model_name == "Codette Fine-Tuned (v9)":
|
| 70 |
-
count = sum(1 for line in chat_memory[session_id] if line.startswith("🖋️ You >"))
|
| 71 |
-
if count >= MAX_PROMPTS_PER_SESSION:
|
| 72 |
-
yield "[🛑 Limit] Max 5 prompts per session.", None, None
|
| 73 |
-
return
|
| 74 |
-
now = time.time()
|
| 75 |
-
if now - last_usage_time.get(session_id, 0) < THROTTLE_SECONDS:
|
| 76 |
-
wait = int(THROTTLE_SECONDS - (now - last_usage_time[session_id]))
|
| 77 |
-
yield f"[⏳ Wait] Try again in {wait} sec.", None, None
|
| 78 |
-
return
|
| 79 |
-
last_usage_time[session_id] = now
|
| 80 |
-
|
| 81 |
-
if model_name == "Codette Fine-Tuned (v9)":
|
| 82 |
-
try:
|
| 83 |
-
response = client.chat.completions.create(
|
| 84 |
-
model=AVAILABLE_MODELS[model_name],
|
| 85 |
-
messages=[{"role": "user", "content": prompt}],
|
| 86 |
-
temperature=0.7,
|
| 87 |
-
max_tokens=256
|
| 88 |
-
)
|
| 89 |
-
output = response.choices[0].message.content.strip()
|
| 90 |
-
except Exception as e:
|
| 91 |
-
yield f"[OpenAI error]: {e}", None, None
|
| 92 |
-
return
|
| 93 |
-
else:
|
| 94 |
-
if model_name not in text_model_cache:
|
| 95 |
-
try:
|
| 96 |
-
text_model_cache[model_name] = pipeline(
|
| 97 |
-
"text-generation",
|
| 98 |
-
model=AVAILABLE_MODELS[model_name],
|
| 99 |
-
device=0 if device == "cuda" else -1
|
| 100 |
-
)
|
| 101 |
-
except Exception as e:
|
| 102 |
-
yield f"[Text model error]: {e}", None, None
|
| 103 |
-
return
|
| 104 |
-
try:
|
| 105 |
-
output = text_model_cache[model_name](
|
| 106 |
-
prompt, max_length=100, do_sample=True, num_return_sequences=1
|
| 107 |
-
)[0]['generated_text'].strip()
|
| 108 |
-
except Exception as e:
|
| 109 |
-
yield f"[Generation error]: {e}", None, None
|
| 110 |
-
return
|
| 111 |
|
| 112 |
-
#
|
|
|
|
|
|
|
|
|
|
| 113 |
response_so_far = ""
|
|
|
|
| 114 |
for char in output:
|
|
|
|
| 115 |
response_so_far += char
|
|
|
|
| 116 |
temp_log = chat_memory[session_id][:]
|
|
|
|
| 117 |
temp_log.append(f"🖋️ You > {prompt}")
|
| 118 |
temp_log.append(f"🧠 Codette > {response_so_far}")
|
|
|
|
| 119 |
yield "\n".join(temp_log[-10:]), None, None
|
|
|
|
| 120 |
time.sleep(0.01)
|
| 121 |
|
|
|
|
| 122 |
chat_memory[session_id].append(f"🖋️ You > {prompt}")
|
| 123 |
chat_memory[session_id].append(f"🧠 Codette > {output}")
|
| 124 |
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
if generate_image and image_enabled:
|
|
|
|
| 128 |
try:
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
imgs = result.images
|
|
|
|
| 131 |
except Exception as e:
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
if generate_video and video_enabled:
|
|
|
|
| 135 |
try:
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
frames = result.frames
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
imageio.mimsave(temp_video_path, frames, fps=fps)
|
|
|
|
| 140 |
vid = temp_video_path
|
|
|
|
| 141 |
except Exception as e:
|
| 142 |
-
|
|
|
|
|
|
|
| 143 |
|
| 144 |
yield "\n".join(chat_memory[session_id][-10:]), imgs, vid
|
| 145 |
|
| 146 |
-
# ---------- Gradio UI ----------
|
| 147 |
-
with gr.Blocks(title="🧬 Codette Terminal – Streamed AI Chat") as demo:
|
| 148 |
-
gr.Markdown("## 🧬 Codette Terminal (Chat + Image + Video + Fine-Tuned AI)")
|
| 149 |
-
gr.Markdown("Type a prompt, choose a model, and generate responses. Type `'exit'` to reset the session.")
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
with gr.Row():
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
with gr.Row():
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
)
|
| 170 |
|
| 171 |
with gr.Row():
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
with gr.Row():
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
user_input.submit(
|
| 179 |
-
|
|
|
|
|
|
|
| 180 |
inputs=[
|
| 181 |
-
user_input,
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
],
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
)
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
if __name__ == "__main__":
|
| 189 |
-
demo.launch(
|
|
|
|
| 4 |
import torch
|
| 5 |
import time
|
| 6 |
import os
|
| 7 |
+
|
| 8 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 9 |
+
from peft import PeftModel
|
| 10 |
from diffusers import DiffusionPipeline
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# -------------------------------------------------
|
| 14 |
+
# Device Setup
|
| 15 |
+
# -------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 18 |
+
|
| 19 |
text_model_cache = {}
|
| 20 |
chat_memory = {}
|
|
|
|
| 21 |
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# -------------------------------------------------
|
| 24 |
+
# Available Text Models
|
| 25 |
+
# -------------------------------------------------
|
| 26 |
+
|
| 27 |
+
AVAILABLE_MODELS = {
|
| 28 |
+
"Codette LoRA (Llama-3.1)": "codette_lora",
|
| 29 |
+
"Mistral-7B Instruct": "mistralai/Mistral-7B-Instruct-v0.2",
|
| 30 |
+
"Phi-3 Mini": "microsoft/phi-3-mini-4k-instruct",
|
| 31 |
+
"GPT-2 (lightweight)": "gpt2"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# -------------------------------------------------
|
| 36 |
+
# Load Codette LoRA Adapter
|
| 37 |
+
# -------------------------------------------------
|
| 38 |
+
|
| 39 |
+
def load_codette_lora():
|
| 40 |
+
|
| 41 |
+
base_model = "meta-llama/Meta-Llama-3.1-8B"
|
| 42 |
+
|
| 43 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
| 44 |
+
|
| 45 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 46 |
+
base_model,
|
| 47 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
| 48 |
+
device_map="auto"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
model = PeftModel.from_pretrained(
|
| 52 |
+
model,
|
| 53 |
+
"Raiff1982/codette-lora-adapters"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
pipe = pipeline(
|
| 57 |
+
"text-generation",
|
| 58 |
+
model=model,
|
| 59 |
+
tokenizer=tokenizer,
|
| 60 |
+
device_map="auto"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
return pipe
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# -------------------------------------------------
|
| 67 |
+
# Image Generator (SDXL Turbo)
|
| 68 |
+
# -------------------------------------------------
|
| 69 |
+
|
| 70 |
try:
|
| 71 |
+
|
| 72 |
image_generator = DiffusionPipeline.from_pretrained(
|
| 73 |
+
"stabilityai/sdxl-turbo",
|
| 74 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
| 75 |
+
variant="fp16" if device == "cuda" else None
|
| 76 |
)
|
| 77 |
+
|
| 78 |
image_generator.to(device)
|
| 79 |
+
|
| 80 |
image_enabled = True
|
| 81 |
+
|
| 82 |
except Exception as e:
|
| 83 |
+
|
| 84 |
print(f"[Image Model Load Error]: {e}")
|
| 85 |
image_generator = None
|
| 86 |
image_enabled = False
|
| 87 |
|
| 88 |
+
|
| 89 |
+
# -------------------------------------------------
|
| 90 |
+
# Video Generator (Zeroscope)
|
| 91 |
+
# -------------------------------------------------
|
| 92 |
+
|
| 93 |
try:
|
| 94 |
+
|
| 95 |
video_pipeline = DiffusionPipeline.from_pretrained(
|
| 96 |
+
"cerspense/zeroscope_v2_576w",
|
|
|
|
| 97 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
| 98 |
)
|
| 99 |
+
|
| 100 |
video_pipeline.to(device)
|
| 101 |
+
|
| 102 |
video_enabled = True
|
| 103 |
+
|
| 104 |
except Exception as e:
|
| 105 |
+
|
| 106 |
print(f"[Video Model Load Error]: {e}")
|
| 107 |
video_pipeline = None
|
| 108 |
video_enabled = False
|
| 109 |
|
| 110 |
+
|
| 111 |
+
# -------------------------------------------------
|
| 112 |
+
# Load Text Models
|
| 113 |
+
# -------------------------------------------------
|
| 114 |
+
|
| 115 |
+
def get_text_model(model_name):
|
| 116 |
+
|
| 117 |
+
if model_name not in text_model_cache:
|
| 118 |
+
|
| 119 |
+
if AVAILABLE_MODELS[model_name] == "codette_lora":
|
| 120 |
+
|
| 121 |
+
text_model_cache[model_name] = load_codette_lora()
|
| 122 |
+
|
| 123 |
+
else:
|
| 124 |
+
|
| 125 |
+
text_model_cache[model_name] = pipeline(
|
| 126 |
+
"text-generation",
|
| 127 |
+
model=AVAILABLE_MODELS[model_name],
|
| 128 |
+
device=0 if device == "cuda" else -1
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
return text_model_cache[model_name]
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
# -------------------------------------------------
|
| 135 |
+
# Codette Terminal Logic
|
| 136 |
+
# -------------------------------------------------
|
| 137 |
+
|
| 138 |
+
def codette_terminal(prompt, model_name, generate_image, generate_video,
|
| 139 |
+
session_id, batch_size, video_steps, fps):
|
| 140 |
+
|
| 141 |
if session_id not in chat_memory:
|
| 142 |
chat_memory[session_id] = []
|
| 143 |
|
| 144 |
if prompt.lower() in ["exit", "quit"]:
|
| 145 |
chat_memory[session_id] = []
|
| 146 |
+
yield "🧠 Codette session reset.", None, None
|
| 147 |
+
return
|
| 148 |
+
|
| 149 |
+
try:
|
| 150 |
+
|
| 151 |
+
model = get_text_model(model_name)
|
| 152 |
+
|
| 153 |
+
result = model(
|
| 154 |
+
prompt,
|
| 155 |
+
max_new_tokens=200,
|
| 156 |
+
temperature=0.7,
|
| 157 |
+
top_p=0.9,
|
| 158 |
+
do_sample=True
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
output = result[0]["generated_text"]
|
| 162 |
+
|
| 163 |
+
except Exception as e:
|
| 164 |
+
|
| 165 |
+
yield f"[Text generation error]: {e}", None, None
|
| 166 |
return
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
+
# -------------------------------------------------
|
| 170 |
+
# Stream Text
|
| 171 |
+
# -------------------------------------------------
|
| 172 |
+
|
| 173 |
response_so_far = ""
|
| 174 |
+
|
| 175 |
for char in output:
|
| 176 |
+
|
| 177 |
response_so_far += char
|
| 178 |
+
|
| 179 |
temp_log = chat_memory[session_id][:]
|
| 180 |
+
|
| 181 |
temp_log.append(f"🖋️ You > {prompt}")
|
| 182 |
temp_log.append(f"🧠 Codette > {response_so_far}")
|
| 183 |
+
|
| 184 |
yield "\n".join(temp_log[-10:]), None, None
|
| 185 |
+
|
| 186 |
time.sleep(0.01)
|
| 187 |
|
| 188 |
+
|
| 189 |
chat_memory[session_id].append(f"🖋️ You > {prompt}")
|
| 190 |
chat_memory[session_id].append(f"🧠 Codette > {output}")
|
| 191 |
|
| 192 |
+
|
| 193 |
+
imgs = None
|
| 194 |
+
vid = None
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
# -------------------------------------------------
|
| 198 |
+
# Image Generation
|
| 199 |
+
# -------------------------------------------------
|
| 200 |
|
| 201 |
if generate_image and image_enabled:
|
| 202 |
+
|
| 203 |
try:
|
| 204 |
+
|
| 205 |
+
result = image_generator(
|
| 206 |
+
prompt,
|
| 207 |
+
num_images_per_prompt=batch_size,
|
| 208 |
+
num_inference_steps=2
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
imgs = result.images
|
| 212 |
+
|
| 213 |
except Exception as e:
|
| 214 |
+
|
| 215 |
+
print(f"[Image error]: {e}")
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
# -------------------------------------------------
|
| 219 |
+
# Video Generation
|
| 220 |
+
# -------------------------------------------------
|
| 221 |
|
| 222 |
if generate_video and video_enabled:
|
| 223 |
+
|
| 224 |
try:
|
| 225 |
+
|
| 226 |
+
result = video_pipeline(
|
| 227 |
+
prompt,
|
| 228 |
+
num_inference_steps=video_steps
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
frames = result.frames
|
| 232 |
+
|
| 233 |
+
temp_video_path = tempfile.NamedTemporaryFile(
|
| 234 |
+
suffix=".mp4",
|
| 235 |
+
delete=False
|
| 236 |
+
).name
|
| 237 |
+
|
| 238 |
imageio.mimsave(temp_video_path, frames, fps=fps)
|
| 239 |
+
|
| 240 |
vid = temp_video_path
|
| 241 |
+
|
| 242 |
except Exception as e:
|
| 243 |
+
|
| 244 |
+
print(f"[Video error]: {e}")
|
| 245 |
+
|
| 246 |
|
| 247 |
yield "\n".join(chat_memory[session_id][-10:]), imgs, vid
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
+
# -------------------------------------------------
|
| 251 |
+
# Gradio Interface
|
| 252 |
+
# -------------------------------------------------
|
| 253 |
|
| 254 |
+
with gr.Blocks(title="🧬 Codette Terminal") as demo:
|
| 255 |
+
|
| 256 |
+
gr.Markdown("## 🧬 Codette Terminal")
|
| 257 |
+
gr.Markdown("Chat with Codette, generate images, and create short videos.")
|
| 258 |
+
|
| 259 |
+
session_id = gr.Textbox(value="default_session", visible=False)
|
| 260 |
|
| 261 |
with gr.Row():
|
| 262 |
+
|
| 263 |
+
model_dropdown = gr.Dropdown(
|
| 264 |
+
choices=list(AVAILABLE_MODELS.keys()),
|
| 265 |
+
value="Codette LoRA (Llama-3.1)",
|
| 266 |
+
label="Language Model"
|
| 267 |
+
)
|
| 268 |
|
| 269 |
with gr.Row():
|
| 270 |
+
|
| 271 |
+
generate_image_toggle = gr.Checkbox(
|
| 272 |
+
label="Generate Image(s)",
|
| 273 |
+
value=False,
|
| 274 |
+
interactive=image_enabled
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
generate_video_toggle = gr.Checkbox(
|
| 278 |
+
label="Generate Video",
|
| 279 |
+
value=False,
|
| 280 |
+
interactive=video_enabled
|
| 281 |
)
|
| 282 |
|
| 283 |
with gr.Row():
|
| 284 |
+
|
| 285 |
+
batch_size_slider = gr.Slider(
|
| 286 |
+
label="Number of Images",
|
| 287 |
+
minimum=1,
|
| 288 |
+
maximum=4,
|
| 289 |
+
step=1,
|
| 290 |
+
value=1
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
video_steps_slider = gr.Slider(
|
| 294 |
+
label="Video Inference Steps",
|
| 295 |
+
minimum=10,
|
| 296 |
+
maximum=50,
|
| 297 |
+
step=10,
|
| 298 |
+
value=20
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
fps_slider = gr.Slider(
|
| 302 |
+
label="Video FPS",
|
| 303 |
+
minimum=4,
|
| 304 |
+
maximum=24,
|
| 305 |
+
step=2,
|
| 306 |
+
value=8
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
user_input = gr.Textbox(
|
| 310 |
+
label="Your Prompt",
|
| 311 |
+
placeholder="A robot dreaming on Mars...",
|
| 312 |
+
lines=1
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
output_text = gr.Textbox(
|
| 316 |
+
label="Codette Output",
|
| 317 |
+
lines=15,
|
| 318 |
+
interactive=False
|
| 319 |
+
)
|
| 320 |
|
| 321 |
with gr.Row():
|
| 322 |
+
|
| 323 |
+
output_image = gr.Gallery(
|
| 324 |
+
label="Generated Images",
|
| 325 |
+
columns=2
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
output_video = gr.Video(
|
| 329 |
+
label="Generated Video"
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
|
| 333 |
user_input.submit(
|
| 334 |
+
|
| 335 |
+
codette_terminal,
|
| 336 |
+
|
| 337 |
inputs=[
|
| 338 |
+
user_input,
|
| 339 |
+
model_dropdown,
|
| 340 |
+
generate_image_toggle,
|
| 341 |
+
generate_video_toggle,
|
| 342 |
+
session_id,
|
| 343 |
+
batch_size_slider,
|
| 344 |
+
video_steps_slider,
|
| 345 |
+
fps_slider
|
| 346 |
],
|
| 347 |
+
|
| 348 |
+
outputs=[
|
| 349 |
+
output_text,
|
| 350 |
+
output_image,
|
| 351 |
+
output_video
|
| 352 |
+
]
|
| 353 |
+
|
| 354 |
)
|
| 355 |
|
| 356 |
+
|
| 357 |
+
# -------------------------------------------------
|
| 358 |
+
# Launch
|
| 359 |
+
# -------------------------------------------------
|
| 360 |
+
|
| 361 |
if __name__ == "__main__":
|
| 362 |
+
demo.launch()
|