testdeep123 commited on
Commit
566d051
·
verified ·
1 Parent(s): b73ae14

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -0
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import json
4
+ import time
5
+
6
+ def generate_video(prompt, aspect_ratio):
7
+ # Prepare the API key and base URL
8
+ BASE_URL = "https://generativelanguage.googleapis.com/v1beta"
9
+ API_KEY = "AIzaSyDljfPA5gl7zn11UamTPllqdX13-q85ZgY" # Note: You should use environment variables for the API key
10
+
11
+ # Prepare the request data
12
+ request_data = {
13
+ "instances": [{
14
+ "prompt": prompt
15
+ }],
16
+ "parameters": {
17
+ "aspectRatio": aspect_ratio,
18
+ "personGeneration": "dont_allow",
19
+ }
20
+ }
21
+
22
+ try:
23
+ # Prepare the curl command
24
+ curl_command = [
25
+ "curl",
26
+ f"{BASE_URL}/models/veo-2.0-generate-001:predictLongRunning?key={API_KEY}",
27
+ "-H", "Content-Type: application/json",
28
+ "-X", "POST",
29
+ "-d", json.dumps(request_data)
30
+ ]
31
+
32
+ # Execute the curl command
33
+ result = subprocess.run(curl_command, capture_output=True, text=True)
34
+
35
+ if result.returncode != 0:
36
+ return f"Error: {result.stderr}"
37
+
38
+ # Parse the response
39
+ response = json.loads(result.stdout)
40
+ operation_name = response.get("name", "")
41
+
42
+ # Return the operation name and full response
43
+ return f"Operation Name: {operation_name}\n\nFull Response:\n{json.dumps(response, indent=2)}"
44
+
45
+ except Exception as e:
46
+ return f"An error occurred: {str(e)}"
47
+
48
+ # Create the Gradio interface
49
+ with gr.Blocks() as demo:
50
+ gr.Markdown("# Veo Video Generation API")
51
+ gr.Markdown("Enter your prompt and select aspect ratio to generate a video using Google's Veo API.")
52
+
53
+ with gr.Row():
54
+ with gr.Column():
55
+ prompt = gr.Textbox(label="Video Prompt", placeholder="Describe the video you want to generate...")
56
+ aspect_ratio = gr.Dropdown(
57
+ label="Aspect Ratio",
58
+ choices=["16:9", "9:16", "1:1", "4:3", "3:4"],
59
+ value="16:9"
60
+ )
61
+ submit_btn = gr.Button("Generate Video")
62
+
63
+ with gr.Column():
64
+ output = gr.Textbox(label="API Response", interactive=False, lines=10)
65
+
66
+ submit_btn.click(
67
+ fn=generate_video,
68
+ inputs=[prompt, aspect_ratio],
69
+ outputs=output
70
+ )
71
+
72
+ gr.Examples(
73
+ examples=[
74
+ ["Panning wide shot of a calico kitten sleeping in the sunshine", "16:9"],
75
+ ["Aerial view of a tropical beach at sunset", "16:9"],
76
+ ["Close-up of a chef preparing sushi in a restaurant kitchen", "9:16"]
77
+ ],
78
+ inputs=[prompt, aspect_ratio]
79
+ )
80
+
81
+ # Launch the interface
82
+ if __name__ == "__main__":
83
+ demo.launch()