Update a.py
Browse files3 unmodified lines456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140118 unmodified lines2592602612622632642652662672682692703 unmodified linesfrom byteplussdkarkruntime import Arkimport httpximport socket# Get API key from Hugging Face secret "Key"API_KEY = os.environ.get("Key", "")#base_url="https://ark.ap-southeast.bytepluses.com/api/v3"# Initialize client with better timeout and retry settingsclient = Ark(base_url="https://1hit.no/proxy/proxy.php",api_key=API_KEY,timeout=30.0, # Shorter timeout to fail fastermax_retries=3,)# Fresh new promptsDEFAULT_PROMPTS = {"Cinematic Nature": "Majestic drone shot soaring above misty mountains at golden hour, sunlight breaking through clouds, cinematic 4k quality, smooth motion --duration 5 --camerafixed false","Urban Exploration": "Dynamic drone flight through narrow alleyways of a neon-lit Tokyo street at night, rain-slicked surfaces reflecting lights, cyberpunk aesthetic --duration 5 --camerafixed false","Action Sequence": "High-speed drone chasing a sports car through a winding coastal road, dramatic cliffside views, action movie style --duration 5 --camerafixed false","Abstract Art": "Surreal drone flight through floating geometric shapes in a dreamlike void, pastel colors, ethereal atmosphere --duration 5 --camerafixed false","Wildlife Documentary": "Drone following a herd of elephants across the African savanna at sunset, National Geographic style, majestic wildlife cinematography --duration 5 --camerafixed false","Sports Highlight": "Drone racing alongside professional skiers carving through fresh powder in the Alps, high-energy sports broadcast style --duration 5 --camerafixed false","Beach Paradise": "Drone gliding over turquoise waters and white sand beaches, palm trees swaying, tropical paradise aerial view --duration 5 --camerafixed false","Ancient Temple": "Drone circling around ancient Angkor Wat temple at dawn, mystical atmosphere, historical documentary style --duration 5 --camerafixed false"}def test_connection():"""Test if we can reach the API before trying"""try:socket.gethostbyname('ark.ap-southeast.bytepluses.com')return True, "DNS resolved"except Exception as e:return False, f"DNS failed: {e}"def generate_video(image_path, prompt_text, progress=gr.Progress()):"""Generate video with robust error handling"""# Test connection firstconn_ok, conn_msg = test_connection()if not conn_ok:yield f"❌ Connection Error: {conn_msg}. This might be a network restriction from Hugging Face.", Nonereturnif not API_KEY:yield "❌ API Key not configured. Please add 'Key' secret.", Nonereturnif image_path is None:yield "⚠️ Please upload an image first", Nonereturntry:progress(0, desc="Preparing image...")# Get HF temp URLimage_url = f"/file={image_path}"print(f"Using image URL: {image_url}")yield "✅ Image ready! Creating video request...", Noneprogress(0.2, desc="Creating request...")# Create task with timeouttry:create_result = client.content_generation.tasks.create(model="seedance-1-5-pro-251215",content=[{"type": "text","text": prompt_text},{"type": "image_url","image_url": {"url": image_url}}])except Exception as e:error_str = str(e)if "Connection error" in error_str or "202602" in error_str:yield f"❌ Network Error: Cannot reach BytePlus API. This is likely a Hugging Face network restriction.", Noneelse:yield f"❌ API Error: {error_str}", Nonereturntask_id = create_result.idprint(f"Task created: {task_id}")yield f"✅ Task created: {task_id}", Noneprogress(0.3, desc="Polling for results...")import timeimport gradio as grfrom byteplussdkarkruntime import Arkimport httpximport socketimport requests # Added for JSON polling# Get API key from Hugging Face secret "Key"API_KEY = os.environ.get("Key", "")#base_url="https://ark.ap-southeast.bytepluses.com/api/v3"# Initialize client with better timeout and retry settingsclient = Ark(base_url="https://1hit.no/proxy/proxy.php",api_key=API_KEY,timeout=30.0, # Shorter timeout to fail fastermax_retries=3,)# Fresh new promptsDEFAULT_PROMPTS = {"Cinematic Nature": "Majestic drone shot soaring above misty mountains at golden hour, sunlight breaking through clouds, cinematic 4k quality, smooth motion --duration 5 --camerafixed false","Urban Exploration": "Dynamic drone flight through narrow alleyways of a neon-lit Tokyo street at night, rain-slicked surfaces reflecting lights, cyberpunk aesthetic --duration 5 --camerafixed false","Action Sequence": "High-speed drone chasing a sports car through a winding coastal road, dramatic cliffside views, action movie style --duration 5 --camerafixed false","Abstract Art": "Surreal drone flight through floating geometric shapes in a dreamlike void, pastel colors, ethereal atmosphere --duration 5 --camerafixed false","Wildlife Documentary": "Drone following a herd of elephants across the African savanna at sunset, National Geographic style, majestic wildlife cinematography --duration 5 --camerafixed false","Sports Highlight": "Drone racing alongside professional skiers carving through fresh powder in the Alps, high-energy sports broadcast style --duration 5 --camerafixed false","Beach Paradise": "Drone gliding over turquoise waters and white sand beaches, palm trees swaying, tropical paradise aerial view --duration 5 --camerafixed false","Ancient Temple": "Drone circling around ancient Angkor Wat temple at dawn, mystical atmosphere, historical documentary style --duration 5 --camerafixed false"}118 unmodified linesif video_url:yield "✅ Video generated successfully! (via JSON)", video_urlreturnelif video_url is None: # Failedyield "❌ Task failed (via JSON)", Nonereturnelse: # Still processingyield f"⏳ Status: processing... (JSON fallback)", Nonetime.sleep(5) # Poll JSON less frequentlyattempts += 1yield "⏰ Timeout after 2 minutes", None3 unmodified lines45678910111213141516171819202122232425262728293031118 unmodified lines1501511521531541551561571581591601613 unmodified linesfrom byteplussdkarkruntime import Arkimport httpximport socketimport requests# Get API key from Hugging Face secret "Key"API_KEY = os.environ.get("Key", "")# Initialize client with proxyclient = Ark(base_url="https://1hit.no/proxy/proxy.php",api_key=API_KEY,timeout=30.0,max_retries=3,)# Fresh new promptsDEFAULT_PROMPTS = {"Cinematic Nature": "Majestic drone shot soaring above misty mountains at golden hour, sunlight breaking through clouds, cinematic 4k quality, smooth motion --duration 5 --camerafixed false","Urban Exploration": "Dynamic drone flight through narrow alleyways of a neon-lit Tokyo street at night, rain-slicked surfaces reflecting lights, cyberpunk aesthetic --duration 5 --camerafixed false","Action Sequence": "High-speed drone chasing a sports car through a winding coastal road, dramatic cliffside views, action movie style --duration 5 --camerafixed false","Abstract Art": "Surreal drone flight through floating geometric shapes in a dreamlike void, pastel colors, ethereal atmosphere --duration 5 --camerafixed false","Wildlife Documentary": "Drone following a herd of elephants across the African savanna at sunset, National Geographic style, majestic wildlife cinematography --duration 5 --camerafixed false","Sports Highlight": "Drone racing alongside professional skiers carving through fresh powder in the Alps, high-energy sports broadcast style --duration 5 --camerafixed false","Beach Paradise": "Drone gliding over turquoise waters and white sand beaches, palm trees swaying, tropical paradise aerial view --duration 5 --camerafixed false","Ancient Temple": "Drone circling around ancient Angkor Wat temple at dawn, mystical atmosphere, historical documentary style --duration 5 --camerafixed false"}118 unmodified linesif video_url:yield "✅ Video generated successfully! (via JSON)", video_urlreturnelif video_url is None:yield "❌ Task failed (via JSON)", Nonereturnelse:yield f"⏳ Status: processing... (JSON fallback)", Nonetime.sleep(5)attempts += 1yield "⏰ Timeout after 2 minutes", None
a.py+6-115