Spaces:
Paused
Paused
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,103 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Text Agent Enhancement - Visual Prompts in English Only
|
| 3 |
-
========================================================
|
| 4 |
-
This patch ensures visual_prompt is ALWAYS in English and detailed
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
# Add this to app_41.py in the system_prompt
|
| 8 |
-
|
| 9 |
-
ENHANCED_SYSTEM_PROMPT = """You are a professional narrative analyzer for video production.
|
| 10 |
-
|
| 11 |
-
Analyze the text and divide it into meaningful scenes for video production.
|
| 12 |
-
|
| 13 |
-
CRITICAL RULES FOR VISUAL PROMPTS:
|
| 14 |
-
1. visual_prompt MUST be in ENGLISH - NEVER in Arabic or any other language
|
| 15 |
-
2. visual_prompt MUST be detailed and descriptive (minimum 10 words)
|
| 16 |
-
3. visual_prompt should describe:
|
| 17 |
-
- Main subjects/characters
|
| 18 |
-
- Setting/environment
|
| 19 |
-
- Mood/atmosphere
|
| 20 |
-
- Key visual elements
|
| 21 |
-
- Composition hints
|
| 22 |
-
|
| 23 |
-
Example of GOOD visual_prompt:
|
| 24 |
-
"ancient magical forest with towering trees, glowing mushrooms on mossy ground, wise old owl perched on branch, ethereal mist, mystical atmosphere, moonlight filtering through canopy"
|
| 25 |
-
|
| 26 |
-
Example of BAD visual_prompt:
|
| 27 |
-
"غابة سحرية مع بومة" ← Arabic - WRONG!
|
| 28 |
-
"forest with owl" ← Too short - WRONG!
|
| 29 |
-
|
| 30 |
-
OTHER RULES:
|
| 31 |
-
1. Each scene = complete, self-contained moment/idea
|
| 32 |
-
2. Scene text can be in the INPUT LANGUAGE ({input_data.language})
|
| 33 |
-
3. text_english MUST be accurate English translation
|
| 34 |
-
4. Target duration: {input_data.target_scene_duration}±5 seconds
|
| 35 |
-
5. Visual style will be added automatically: {input_data.visual_style or DEFAULT_VISUAL_STYLE}
|
| 36 |
-
|
| 37 |
-
Output ONLY valid JSON:
|
| 38 |
-
[
|
| 39 |
-
{{
|
| 40 |
-
"scene_id": 1,
|
| 41 |
-
"text": "Original text in input language",
|
| 42 |
-
"text_english": "Accurate English translation",
|
| 43 |
-
"visual_prompt": "DETAILED ENGLISH visual description (10+ words)",
|
| 44 |
-
"estimated_duration_sec": 15
|
| 45 |
-
}}
|
| 46 |
-
]
|
| 47 |
-
|
| 48 |
-
REMEMBER: visual_prompt = ENGLISH + DETAILED (10+ words)
|
| 49 |
-
"""
|
| 50 |
-
|
| 51 |
-
# Example validation function to add:
|
| 52 |
-
|
| 53 |
-
def validate_visual_prompt(prompt: str, scene_id: int) -> str:
|
| 54 |
-
"""
|
| 55 |
-
Validate and fix visual_prompt
|
| 56 |
-
Returns: Corrected prompt in English
|
| 57 |
-
"""
|
| 58 |
-
import re
|
| 59 |
-
|
| 60 |
-
# Check for Arabic characters
|
| 61 |
-
has_arabic = bool(re.search(r'[\u0600-\u06FF]', prompt))
|
| 62 |
-
|
| 63 |
-
if has_arabic:
|
| 64 |
-
print(f"⚠️ Scene {scene_id}: visual_prompt contains Arabic!")
|
| 65 |
-
print(f" Original: {prompt}")
|
| 66 |
-
# Return generic English prompt
|
| 67 |
-
return "cinematic scene, detailed environment, professional composition"
|
| 68 |
-
|
| 69 |
-
# Check length
|
| 70 |
-
word_count = len(prompt.split())
|
| 71 |
-
if word_count < 10:
|
| 72 |
-
print(f"⚠️ Scene {scene_id}: visual_prompt too short ({word_count} words)")
|
| 73 |
-
# Add generic descriptors
|
| 74 |
-
prompt = f"{prompt}, detailed, cinematic lighting, professional composition, high quality"
|
| 75 |
-
|
| 76 |
-
return prompt
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
# Use in _parse_claude_response:
|
| 80 |
-
|
| 81 |
-
def _parse_claude_response(self, content: str) -> List[Scene]:
|
| 82 |
-
"""Parse Claude JSON response with validation"""
|
| 83 |
-
import json
|
| 84 |
-
import re
|
| 85 |
-
|
| 86 |
-
content = re.sub(r'^```json\s*', '', content.strip())
|
| 87 |
-
content = re.sub(r'\s*```$', '', content)
|
| 88 |
-
|
| 89 |
-
scenes_data = json.loads(content)
|
| 90 |
-
|
| 91 |
-
if not isinstance(scenes_data, list):
|
| 92 |
-
raise ValueError("Response is not a list")
|
| 93 |
-
|
| 94 |
-
# Validate and fix visual_prompts
|
| 95 |
-
for scene_data in scenes_data:
|
| 96 |
-
if 'visual_prompt' in scene_data:
|
| 97 |
-
original = scene_data['visual_prompt']
|
| 98 |
-
validated = validate_visual_prompt(original, scene_data.get('scene_id', 0))
|
| 99 |
-
if validated != original:
|
| 100 |
-
print(f" Fixed to: {validated[:50]}...")
|
| 101 |
-
scene_data['visual_prompt'] = validated
|
| 102 |
-
|
| 103 |
-
return [Scene(**scene_data) for scene_data in scenes_data]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|