Teamtheo613 commited on
Commit
1535bbd
Β·
verified Β·
1 Parent(s): 0fccf00

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -0
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import os
3
+ import sys
4
+ import subprocess
5
+ import gradio as gr
6
+ import torch
7
+
8
+ sys.path.insert(0, '/app/FunGen')
9
+
10
+ def process_video(video, mode, overwrite, autotune):
11
+ """Process video with FunGen"""
12
+ print(f"[DEBUG] Called with video={video}, mode={mode}, overwrite={overwrite}, autotune={autotune}")
13
+
14
+ if video is None:
15
+ return "❌ No video uploaded", None
16
+
17
+ try:
18
+ input_path = video
19
+ print(f"[DEBUG] Input path: {input_path}")
20
+
21
+ if not os.path.exists(input_path):
22
+ return f"❌ File not found: {input_path}", None
23
+
24
+ file_size_mb = os.path.getsize(input_path) / (1024**2)
25
+ status = f"πŸš€ Processing: {os.path.basename(input_path)}\n"
26
+ status += f"πŸ“ Size: {file_size_mb:.1f} MB\n"
27
+ status += f"βš™οΈ Mode: {mode}\n"
28
+ status += f"⏳ Starting...\n\n"
29
+
30
+ print(f"[DEBUG] Status: {status}")
31
+
32
+ # Build command without fake flags
33
+ cmd = ["python", "/app/FunGen/main.py", input_path, "--mode", mode]
34
+ if overwrite:
35
+ cmd.append("--overwrite")
36
+ if not autotune:
37
+ cmd.append("--no-autotune")
38
+
39
+ print(f"[DEBUG] Command: {' '.join(cmd)}")
40
+
41
+ # Set environment
42
+ env = os.environ.copy()
43
+
44
+ result = subprocess.run(cmd, cwd="/app/FunGen", capture_output=True, text=True, timeout=3600, env=env)
45
+
46
+ print(f"[DEBUG] Return code: {result.returncode}")
47
+ print(f"[DEBUG] STDOUT:\n{result.stdout}")
48
+ print(f"[DEBUG] STDERR:\n{result.stderr}")
49
+
50
+ # Look for output - FunGen saves relative to input or in current directory
51
+ output_file = None
52
+ search_paths = [
53
+ os.path.dirname(input_path), # Same folder as input
54
+ "/app/FunGen",
55
+ "/tmp/outputs",
56
+ os.getcwd()
57
+ ]
58
+
59
+ for search_path in search_paths:
60
+ if os.path.exists(search_path):
61
+ print(f"[DEBUG] Searching: {search_path}")
62
+ for root, dirs, files in os.walk(search_path):
63
+ for f in files:
64
+ print(f"[DEBUG] Found file: {os.path.join(root, f)}")
65
+ if f.endswith(".funscript") and not f.endswith(".roll.funscript"):
66
+ output_file = os.path.join(root, f)
67
+ print(f"[DEBUG] βœ“ Matched funscript: {output_file}")
68
+ break
69
+ if output_file:
70
+ break
71
+ if output_file:
72
+ break
73
+
74
+ if output_file and os.path.exists(output_file):
75
+ status += f"βœ… Complete!\nπŸ“œ {os.path.basename(output_file)}"
76
+ print(f"[DEBUG] Returning: {output_file}")
77
+ return status, output_file
78
+
79
+ # Not found - show the full output for debugging
80
+ status += f"⚠️ No output generated\n\nFull Output:\n{result.stdout}\n\nErrors:\n{result.stderr}"
81
+ return status, None
82
+
83
+ except Exception as e:
84
+ error = f"❌ Exception: {str(e)}"
85
+ print(f"[DEBUG] Exception: {error}")
86
+ import traceback
87
+ print(traceback.format_exc())
88
+ return error, None
89
+
90
+ with gr.Blocks(title="FunGen") as demo:
91
+ gr.Markdown("# 🎬 FunGen - Funscript Generator")
92
+
93
+ with gr.Row():
94
+ gpu_info = "βœ… GPU Available" if torch.cuda.is_available() else "❌ No GPU"
95
+ gr.Textbox(value=gpu_info, label="Status", interactive=False)
96
+
97
+ with gr.Row():
98
+ with gr.Column():
99
+ video_input = gr.File(label="Upload Video", file_types=["video"], type="filepath")
100
+ mode_input = gr.Dropdown(
101
+ ["Hybrid Intelligence Tracker", "Oscillation Detector (Legacy)", "YOLO ROI Tracker"],
102
+ value="Hybrid Intelligence Tracker",
103
+ label="Mode"
104
+ )
105
+ overwrite_input = gr.Checkbox(label="Overwrite", value=False)
106
+ autotune_input = gr.Checkbox(label="Apply Autotune", value=True)
107
+ process_btn = gr.Button("Process Video", variant="primary")
108
+
109
+ with gr.Column():
110
+ status_output = gr.Textbox(label="Status", lines=10, interactive=False)
111
+ file_output = gr.File(label="Download", interactive=False)
112
+
113
+ process_btn.click(
114
+ fn=process_video,
115
+ inputs=[video_input, mode_input, overwrite_input, autotune_input],
116
+ outputs=[status_output, file_output]
117
+ )
118
+
119
+ if __name__ == "__main__":
120
+ demo.queue().launch(server_name="0.0.0.0", server_port=7860, show_error=True)