Skip to content

Instantly share code, notes, and snippets.

@me-suzy
Created April 21, 2025 21:15
Show Gist options
  • Save me-suzy/63c32a241a779a772742aa85f9276307 to your computer and use it in GitHub Desktop.
Save me-suzy/63c32a241a779a772742aa85f9276307 to your computer and use it in GitHub Desktop.
runaway video.py
import requests
import json
import os
import base64
from dotenv import load_dotenv
# Încărcăm variabilele de mediu (trebuie să ai un fișier .env cu API_KEY)
load_dotenv()
# API-ul Runway ML pentru Gen-4 Turbo
API_URL = "https://api.runwayml.com/v1/gen-4/video"
API_KEY = os.getenv("RUNWAY_API_KEY") # Trebuie să obții o cheie API de la Runway
# Calea către imaginea ta
image_path = "d:/family-hugging.jpg"
# Prompt-ul pentru generarea video
prompt = "The happy family begins to move, all four of them stand up from the floor together, and start dancing energetically in the living room. Show their full bodies as they dance with joy, moving their arms and legs."
# Parametrii video
params = {
"prompt": prompt,
"duration": 30, # 30 secunde
"output_format": "mp4",
"cfg_scale": 7.5 # Controlează cât de mult se respectă prompt-ul
}
# Citim și codificăm imaginea
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# Creăm cererea
def generate_video():
try:
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Codificăm imaginea
base64_image = encode_image(image_path)
# Construim payload-ul
payload = {
"input_image": base64_image,
**params
}
# Facem cererea POST
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
video_url = result.get("video_url")
print(f"Video generat cu succes. URL: {video_url}")
# Descărcăm videoclipul
video_response = requests.get(video_url)
with open("family_dancing.mp4", "wb") as video_file:
video_file.write(video_response.content)
print("Video descărcat cu succes ca 'family_dancing.mp4'")
else:
print(f"Eroare: {response.status_code}")
print(response.text)
except Exception as e:
print(f"A apărut o eroare: {str(e)}")
# Rulăm funcția
if __name__ == "__main__":
generate_video()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment