zye0616 commited on
Commit
05e7070
·
1 Parent(s): c57c49d

demo interface

Browse files
Files changed (2) hide show
  1. app.py +9 -1
  2. demo.html +201 -0
app.py CHANGED
@@ -6,7 +6,7 @@ from typing import Optional
6
 
7
  from fastapi import BackgroundTasks, FastAPI, File, Form, HTTPException, UploadFile
8
  from fastapi.middleware.cors import CORSMiddleware
9
- from fastapi.responses import FileResponse, JSONResponse
10
  import uvicorn
11
 
12
  from inference import run_inference
@@ -107,3 +107,11 @@ async def process_video(
107
 
108
  if __name__ == "__main__":
109
  uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=False)
 
 
 
 
 
 
 
 
 
6
 
7
  from fastapi import BackgroundTasks, FastAPI, File, Form, HTTPException, UploadFile
8
  from fastapi.middleware.cors import CORSMiddleware
9
+ from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
10
  import uvicorn
11
 
12
  from inference import run_inference
 
107
 
108
  if __name__ == "__main__":
109
  uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=False)
110
+ @app.get("/", response_class=HTMLResponse)
111
+ async def demo_page() -> str:
112
+ demo_path = Path(__file__).with_name("demo.html")
113
+ try:
114
+ return demo_path.read_text(encoding="utf-8")
115
+ except FileNotFoundError:
116
+ return "<h1>Demo page missing</h1>"
117
+
demo.html ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Mission Console</title>
6
+
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ padding: 0;
11
+ font-family: "Inter", Arial, sans-serif;
12
+ background-color: #121212;
13
+ color: #e0e0e0;
14
+ }
15
+
16
+ h1 {
17
+ text-align: center;
18
+ padding: 20px;
19
+ font-size: 26px;
20
+ color: #f5f5f5;
21
+ margin-bottom: 10px;
22
+ }
23
+
24
+ .container {
25
+ width: 80%;
26
+ max-width: 900px;
27
+ margin: auto;
28
+ background: #1e1e1e;
29
+ padding: 25px;
30
+ border-radius: 12px;
31
+ box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
32
+ }
33
+
34
+ .label {
35
+ font-size: 15px;
36
+ font-weight: 600;
37
+ margin-top: 18px;
38
+ display: block;
39
+ color: #bdbdbd;
40
+ }
41
+
42
+ input[type="text"] {
43
+ width: 100%;
44
+ padding: 12px;
45
+ margin-top: 5px;
46
+ border: 1px solid #2c2c2c;
47
+ background-color: #161616;
48
+ color: #fff;
49
+ font-size: 15px;
50
+ border-radius: 8px;
51
+ }
52
+
53
+ input[type="file"],
54
+ select {
55
+ margin-top: 10px;
56
+ padding: 10px;
57
+ background-color: #161616;
58
+ border: 1px solid #2c2c2c;
59
+ border-radius: 8px;
60
+ color: #f5f5f5;
61
+ width: 100%;
62
+ }
63
+
64
+ button {
65
+ margin-top: 25px;
66
+ width: 100%;
67
+ padding: 14px;
68
+ background-color: #333333;
69
+ border: none;
70
+ color: #f5f5f5;
71
+ font-size: 16px;
72
+ font-weight: 600;
73
+ border-radius: 8px;
74
+ cursor: pointer;
75
+ transition: 0.2s;
76
+ }
77
+
78
+ button:hover {
79
+ background-color: #4f4f4f;
80
+ }
81
+
82
+ .output-section {
83
+ margin-top: 35px;
84
+ padding: 20px;
85
+ border-radius: 12px;
86
+ background-color: #171717;
87
+ border: 1px solid #2a2a2a;
88
+ }
89
+
90
+ #summary {
91
+ margin-top: 10px;
92
+ padding: 14px;
93
+ border: 1px solid #2a2a2a;
94
+ background-color: #111;
95
+ color: #d1d1d1;
96
+ font-size: 15px;
97
+ min-height: 70px;
98
+ white-space: pre-wrap;
99
+ border-radius: 8px;
100
+ }
101
+
102
+ #processedVideo {
103
+ margin-top: 20px;
104
+ width: 100%;
105
+ border: 1px solid #2a2a2a;
106
+ border-radius: 8px;
107
+ background-color: #000;
108
+ }
109
+ </style>
110
+
111
+ </head>
112
+ <body>
113
+
114
+ <h1>Mission Console</h1>
115
+
116
+ <div class="container">
117
+
118
+ <label class="label">MISSION PROMPT</label>
119
+ <input id="missionPrompt" type="text" placeholder="e.g., Track hostile drone movement...">
120
+
121
+ <label class="label">UPLOAD VIDEO (.mp4)</label>
122
+ <input id="videoInput" type="file" accept="video/mp4">
123
+
124
+ <label class="label">OBJECT DETECTOR</label>
125
+ <select id="detectorSelect">
126
+ <option value="owlv2" selected>OWL-V2 (text-conditioned)</option>
127
+ <option value="hf_yolov8">YOLOv8 (COCO classes)</option>
128
+ </select>
129
+
130
+ <button onclick="executeMission()">EXECUTE MISSION</button>
131
+
132
+ <div class="output-section">
133
+ <h2 style="color:#00ffea; margin-bottom:10px;">MISSION SUMMARY</h2>
134
+ <div id="summary">(Awaiting mission results...)</div>
135
+ <h2 style="color:#00ffea; margin-top:25px;">PROCESSED VIDEO FEED</h2>
136
+ <video id="processedVideo" controls></video>
137
+ <div id="status" style="margin-top:15px;color:#ffa95c;font-size:13px;"></div>
138
+ </div>
139
+
140
+ </div>
141
+
142
+ <script>
143
+ const PROCESS_VIDEO_URL = "https://biaslab2025-demo-2025.hf.space/process_video";
144
+
145
+ async function executeMission() {
146
+
147
+ const videoFile = document.getElementById("videoInput").files[0];
148
+ const mission = document.getElementById("missionPrompt").value;
149
+ const detector = document.getElementById("detectorSelect").value;
150
+ const summaryEl = document.getElementById("summary");
151
+ const statusEl = document.getElementById("status");
152
+
153
+ if (!videoFile || !mission) {
154
+ alert("Mission invalid: Upload video and enter mission parameters.");
155
+ return;
156
+ }
157
+
158
+ const formData = new FormData();
159
+ formData.append("video", videoFile);
160
+ formData.append("prompt", mission);
161
+ formData.append("detector", detector);
162
+
163
+ statusEl.textContent = "Dispatching mission to backend...";
164
+ summaryEl.textContent = "(Processing...)";
165
+
166
+ try {
167
+ const response = await fetch(PROCESS_VIDEO_URL, {
168
+ method: "POST",
169
+ body: formData
170
+ });
171
+
172
+ if (!response.ok) {
173
+ let errorDetail = `Request failed (${response.status})`;
174
+ try {
175
+ const errJson = await response.json();
176
+ errorDetail = errJson.error || errorDetail;
177
+ } catch (_) {
178
+ // ignore
179
+ }
180
+ throw new Error(errorDetail);
181
+ }
182
+
183
+ const missionSummary = response.headers.get("x-mission-summary") || "No summary returned.";
184
+ summaryEl.textContent = missionSummary;
185
+
186
+ const videoBlob = await response.blob();
187
+ const videoUrl = URL.createObjectURL(videoBlob);
188
+ const videoEl = document.getElementById("processedVideo");
189
+ videoEl.src = videoUrl;
190
+ videoEl.load();
191
+ statusEl.textContent = "Mission complete.";
192
+ } catch (err) {
193
+ console.error(err);
194
+ summaryEl.textContent = "Mission failed.";
195
+ statusEl.textContent = `Error: ${err.message}`;
196
+ }
197
+ }
198
+ </script>
199
+
200
+ </body>
201
+ </html>