Spaces:
Running
Running
updated
Browse files
app.py
CHANGED
|
@@ -3,18 +3,19 @@ import subprocess
|
|
| 3 |
import gradio as gr
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
| 6 |
-
from PIL import Image
|
| 7 |
import tempfile
|
| 8 |
-
import time
|
| 9 |
import google.generativeai as genai
|
| 10 |
|
| 11 |
# ---------------- GEMINI CONFIG ----------------
|
| 12 |
API_KEY = os.environ.get("GEMINI_API_KEY")
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# ---------------- EFFECT FUNCTIONS ----------------
|
| 16 |
def create_fisheye(frame, strength=0.5):
|
| 17 |
-
# simplified fisheye effect for demo
|
| 18 |
h, w = frame.shape[:2]
|
| 19 |
y, x = np.indices((h, w), dtype=np.float32)
|
| 20 |
cx, cy = w/2, h/2
|
|
@@ -114,12 +115,12 @@ def process_video(video_path, style="equirect", strength=0.7, eye_offset=10, vol
|
|
| 114 |
# ---------------- GEMINI AUTO STYLE ----------------
|
| 115 |
def suggest_style(video_description):
|
| 116 |
try:
|
| 117 |
-
response =
|
| 118 |
-
|
| 119 |
-
contents=[{"text": f"Suggest best VR conversion style (fisheye, spherical, equirectangular) for this video: {video_description}"}]
|
| 120 |
)
|
| 121 |
return response.text.strip().lower()
|
| 122 |
-
except:
|
|
|
|
| 123 |
return "equirect"
|
| 124 |
|
| 125 |
# ---------------- GRADIO UI ----------------
|
|
@@ -131,7 +132,7 @@ with gr.Blocks(title="2D β VR Video Converter") as demo:
|
|
| 131 |
with gr.Row():
|
| 132 |
with gr.Column():
|
| 133 |
video_in = gr.Video(label="Upload Video")
|
| 134 |
-
description = gr.Textbox(label="Video Description (optional)", placeholder="Describe your video
|
| 135 |
auto_style_btn = gr.Button("Auto Suggest Style")
|
| 136 |
style_choice = gr.Radio(["equirect", "fisheye", "spherical"], label="VR Style", value="equirect")
|
| 137 |
strength_slider = gr.Slider(0.3, 1.0, value=0.7, step=0.1, label="Effect Strength")
|
|
@@ -141,7 +142,7 @@ with gr.Blocks(title="2D β VR Video Converter") as demo:
|
|
| 141 |
with gr.Column():
|
| 142 |
output_video = gr.Video(label="VR Side-by-Side Output")
|
| 143 |
status_box = gr.Textbox(label="Status")
|
| 144 |
-
|
| 145 |
def run_auto_style(desc):
|
| 146 |
if not desc.strip():
|
| 147 |
return "equirect"
|
|
@@ -157,3 +158,4 @@ with gr.Blocks(title="2D β VR Video Converter") as demo:
|
|
| 157 |
outputs=[output_video, status_box])
|
| 158 |
|
| 159 |
demo.launch()
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
import tempfile
|
|
|
|
| 7 |
import google.generativeai as genai
|
| 8 |
|
| 9 |
# ---------------- GEMINI CONFIG ----------------
|
| 10 |
API_KEY = os.environ.get("GEMINI_API_KEY")
|
| 11 |
+
if not API_KEY:
|
| 12 |
+
raise ValueError("β GEMINI_API_KEY not set in Hugging Face secrets!")
|
| 13 |
+
|
| 14 |
+
genai.configure(api_key=API_KEY)
|
| 15 |
+
model = genai.GenerativeModel("gemini-2.5-flash")
|
| 16 |
|
| 17 |
# ---------------- EFFECT FUNCTIONS ----------------
|
| 18 |
def create_fisheye(frame, strength=0.5):
|
|
|
|
| 19 |
h, w = frame.shape[:2]
|
| 20 |
y, x = np.indices((h, w), dtype=np.float32)
|
| 21 |
cx, cy = w/2, h/2
|
|
|
|
| 115 |
# ---------------- GEMINI AUTO STYLE ----------------
|
| 116 |
def suggest_style(video_description):
|
| 117 |
try:
|
| 118 |
+
response = model.generate_content(
|
| 119 |
+
f"Suggest best VR conversion style (fisheye, spherical, equirectangular) for this video: {video_description}"
|
|
|
|
| 120 |
)
|
| 121 |
return response.text.strip().lower()
|
| 122 |
+
except Exception as e:
|
| 123 |
+
print("Gemini error:", e)
|
| 124 |
return "equirect"
|
| 125 |
|
| 126 |
# ---------------- GRADIO UI ----------------
|
|
|
|
| 132 |
with gr.Row():
|
| 133 |
with gr.Column():
|
| 134 |
video_in = gr.Video(label="Upload Video")
|
| 135 |
+
description = gr.Textbox(label="Video Description (optional)", placeholder="Describe your video...")
|
| 136 |
auto_style_btn = gr.Button("Auto Suggest Style")
|
| 137 |
style_choice = gr.Radio(["equirect", "fisheye", "spherical"], label="VR Style", value="equirect")
|
| 138 |
strength_slider = gr.Slider(0.3, 1.0, value=0.7, step=0.1, label="Effect Strength")
|
|
|
|
| 142 |
with gr.Column():
|
| 143 |
output_video = gr.Video(label="VR Side-by-Side Output")
|
| 144 |
status_box = gr.Textbox(label="Status")
|
| 145 |
+
|
| 146 |
def run_auto_style(desc):
|
| 147 |
if not desc.strip():
|
| 148 |
return "equirect"
|
|
|
|
| 158 |
outputs=[output_video, status_box])
|
| 159 |
|
| 160 |
demo.launch()
|
| 161 |
+
|