InvictaTill commited on
Commit
676dc08
·
1 Parent(s): 8fe167c

fix: replace AutoPipelineForText2Video with DiffusionPipeline and add custom AI Mind Settings to prompt composer

Browse files
Files changed (1) hide show
  1. app.py +47 -15
app.py CHANGED
@@ -63,18 +63,24 @@ def get_device_info():
63
 
64
  DEVICE = get_device_info()
65
 
66
- def enhance_prompt_with_ai(prompt_text, style_preset):
67
  if not prompt_text or not prompt_text.strip():
68
  return "Please enter a prompt first."
69
 
70
- url = "https://invictatill-invictatill-ai.hf.space/api/v1/chat"
71
-
72
  style_modifiers = STYLE_PRESETS.get(style_preset, "")
73
 
 
 
 
 
 
 
 
74
  system_prompt = (
75
  "You are an expert cinematic prompt engineer for video generation models (like Wan 2.1, LTX-Video, CogVideo). "
76
  "Your task is to rewrite the user's simple prompt into a highly descriptive, visually stunning, "
77
  "and detailed prompt optimized for text-to-video models. "
 
78
  "Include specific details about lighting, camera angle, motion, and atmosphere. "
79
  "Keep it under 75 words. "
80
  "Respond ONLY with the final enhanced prompt. Do NOT include any intro or conversational filler."
@@ -87,9 +93,15 @@ def enhance_prompt_with_ai(prompt_text, style_preset):
87
  payload = {
88
  "message": f"[SYSTEM CONTEXT]\n{system_prompt}\n\nUser: {full_prompt}\n\nAssistant:"
89
  }
90
-
 
 
 
 
 
 
91
  try:
92
- response = requests.post(url, json=payload, timeout=8)
93
  if response.status_code == 200:
94
  data = response.json()
95
  enhanced = data.get("reply") or data.get("choices", [{}])[0].get("message", {}).get("content", "")
@@ -116,26 +128,27 @@ def load_model(model_name: str, progress=gr.Progress()):
116
  progress(0.2, desc=f"Downloading/Loading {model_name}...")
117
 
118
  try:
 
119
  if "wan" in model_id.lower():
120
  try:
121
  from diffusers import WanPipeline
122
  pipe = WanPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
123
  except ImportError:
124
- from diffusers import AutoPipelineForText2Video
125
- pipe = AutoPipelineForText2Video.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
126
  elif "ltx" in model_id.lower():
127
  try:
128
  from diffusers import LTXVideoPipeline
129
  pipe = LTXVideoPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
130
  except ImportError:
131
- from diffusers import AutoPipelineForText2Video
132
- pipe = AutoPipelineForText2Video.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
133
  elif "cogvideo" in model_id.lower():
134
- from diffusers import CogVideoXPipeline
135
- pipe = CogVideoXPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
 
 
 
136
  else:
137
- from diffusers import AutoPipelineForText2Video
138
- pipe = AutoPipelineForText2Video.from_pretrained(
139
  model_id,
140
  torch_dtype=DEVICE["dtype"],
141
  variant="fp16" if DEVICE["device"] == "cuda" else None,
@@ -387,8 +400,27 @@ with gr.Blocks(css=custom_css, title="InvictaTill VideoGen Studio", theme=gr.the
387
  gr.Markdown("### ✍️ Prompt Composer")
388
  prompt = gr.Textbox(label="Describe your scene", placeholder="A cyberpunk drone shot flying through neon-lit Tokyo streets...", lines=4, elem_id="prompt")
389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  with gr.Row():
391
- enhance_btn = gr.Button("✨ Enhance Prompt with InvictaTill AI", variant="secondary")
392
 
393
  negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="blur, distortion, low quality, watermark", lines=2, value="blur, distortion, low quality, watermark, text, bad anatomy, deformed, cartoonish, static")
394
 
@@ -401,7 +433,7 @@ with gr.Blocks(css=custom_css, title="InvictaTill VideoGen Studio", theme=gr.the
401
  # Click Handlers
402
  enhance_btn.click(
403
  fn=enhance_prompt_with_ai,
404
- inputs=[prompt, style_dropdown],
405
  outputs=[prompt]
406
  )
407
 
 
63
 
64
  DEVICE = get_device_info()
65
 
66
+ def enhance_prompt_with_ai(prompt_text, style_preset, ai_url, ai_key, session_id):
67
  if not prompt_text or not prompt_text.strip():
68
  return "Please enter a prompt first."
69
 
 
 
70
  style_modifiers = STYLE_PRESETS.get(style_preset, "")
71
 
72
+ # Standardize URL
73
+ ai_url = (ai_url or "").strip().rstrip("/")
74
+ if not ai_url:
75
+ ai_url = "https://invictatill-invictatill-ai.hf.space"
76
+
77
+ chat_endpoint = f"{ai_url}/api/v1/chat"
78
+
79
  system_prompt = (
80
  "You are an expert cinematic prompt engineer for video generation models (like Wan 2.1, LTX-Video, CogVideo). "
81
  "Your task is to rewrite the user's simple prompt into a highly descriptive, visually stunning, "
82
  "and detailed prompt optimized for text-to-video models. "
83
+ "Use your learned facts, memory context, and knowledge about the user's business if relevant. "
84
  "Include specific details about lighting, camera angle, motion, and atmosphere. "
85
  "Keep it under 75 words. "
86
  "Respond ONLY with the final enhanced prompt. Do NOT include any intro or conversational filler."
 
93
  payload = {
94
  "message": f"[SYSTEM CONTEXT]\n{system_prompt}\n\nUser: {full_prompt}\n\nAssistant:"
95
  }
96
+ if session_id:
97
+ payload["session_id"] = session_id
98
+
99
+ headers = {"Content-Type": "application/json"}
100
+ if ai_key:
101
+ headers["Authorization"] = f"Bearer {ai_key}"
102
+
103
  try:
104
+ response = requests.post(chat_endpoint, json=payload, headers=headers, timeout=12)
105
  if response.status_code == 200:
106
  data = response.json()
107
  enhanced = data.get("reply") or data.get("choices", [{}])[0].get("message", {}).get("content", "")
 
128
  progress(0.2, desc=f"Downloading/Loading {model_name}...")
129
 
130
  try:
131
+ from diffusers import DiffusionPipeline
132
  if "wan" in model_id.lower():
133
  try:
134
  from diffusers import WanPipeline
135
  pipe = WanPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
136
  except ImportError:
137
+ pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
 
138
  elif "ltx" in model_id.lower():
139
  try:
140
  from diffusers import LTXVideoPipeline
141
  pipe = LTXVideoPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
142
  except ImportError:
143
+ pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
 
144
  elif "cogvideo" in model_id.lower():
145
+ try:
146
+ from diffusers import CogVideoXPipeline
147
+ pipe = CogVideoXPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
148
+ except ImportError:
149
+ pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=DEVICE["dtype"])
150
  else:
151
+ pipe = DiffusionPipeline.from_pretrained(
 
152
  model_id,
153
  torch_dtype=DEVICE["dtype"],
154
  variant="fp16" if DEVICE["device"] == "cuda" else None,
 
400
  gr.Markdown("### ✍️ Prompt Composer")
401
  prompt = gr.Textbox(label="Describe your scene", placeholder="A cyberpunk drone shot flying through neon-lit Tokyo streets...", lines=4, elem_id="prompt")
402
 
403
+ with gr.Accordion("🧠 InvictaTill AI Mind Integration Settings", open=False):
404
+ gr.Markdown("Configure the endpoint URL and API Key for your running InvictaTill AI Space instance so the prompt enhancer can read your business insights and custom memories.")
405
+ ai_url_input = gr.Textbox(
406
+ value=os.environ.get("VITE_INVICTATILL_AI_URL", "https://invictatill-invictatill-ai.hf.space"),
407
+ label="AI Mind Endpoint URL",
408
+ placeholder="https://invictatill-invictatill-ai.hf.space"
409
+ )
410
+ ai_key_input = gr.Textbox(
411
+ value=os.environ.get("VITE_INVICTATILL_AI_KEY", ""),
412
+ label="API Key / Auth Token",
413
+ placeholder="invicta_sk_...",
414
+ type="password"
415
+ )
416
+ session_id_input = gr.Textbox(
417
+ value="videogen_studio_session",
418
+ label="Session ID (Loads Memory Context)",
419
+ placeholder="videogen_studio_session"
420
+ )
421
+
422
  with gr.Row():
423
+ enhance_btn = gr.Button("✨ Enhance Prompt with InvictaTill AI Mind", variant="secondary")
424
 
425
  negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="blur, distortion, low quality, watermark", lines=2, value="blur, distortion, low quality, watermark, text, bad anatomy, deformed, cartoonish, static")
426
 
 
433
  # Click Handlers
434
  enhance_btn.click(
435
  fn=enhance_prompt_with_ai,
436
+ inputs=[prompt, style_dropdown, ai_url_input, ai_key_input, session_id_input],
437
  outputs=[prompt]
438
  )
439