Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,8 @@
|
|
1 |
import os
|
2 |
import time
|
3 |
from typing import List, Tuple, Optional
|
4 |
-
from pathlib import Path
|
5 |
-
|
6 |
import google.generativeai as genai
|
7 |
import gradio as gr
|
8 |
-
from PIL import Image
|
9 |
-
|
10 |
|
11 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
12 |
|
@@ -21,10 +17,7 @@ Repetitions and Sets: Count the number of repetitions and sets for each exercise
|
|
21 |
Pacing and Timing: Evaluate the pacing and timing of the exercises. Suggest any adjustments needed to optimize performance.
|
22 |
Overall Performance: Give an overall assessment of the workout, highlighting strengths and areas for improvement.
|
23 |
Remember to be encouraging and supportive in your feedback. Your goal is to help them improve and stay motivated. Thank you!
|
24 |
-
"""
|
25 |
-
#If the image does not show an exercise, respond with: 'What are you doing? This is no time for games! Upload a real exercise video.'
|
26 |
-
|
27 |
-
|
28 |
|
29 |
def preprocess_stop_sequences(stop_sequences: str) -> Optional[List[str]]:
|
30 |
if not stop_sequences:
|
@@ -73,7 +66,7 @@ def bot(
|
|
73 |
video_file = genai.get_file(video_file.name)
|
74 |
|
75 |
if video_file.state.name == "FAILED":
|
76 |
-
|
77 |
|
78 |
response = model.generate_content(
|
79 |
contents=[video_file, combined_prompt],
|
@@ -89,7 +82,6 @@ def bot(
|
|
89 |
generation_config=generation_config)
|
90 |
response.resolve()
|
91 |
|
92 |
-
|
93 |
# streaming effect
|
94 |
chatbot[-1][1] = ""
|
95 |
for chunk in response:
|
@@ -180,9 +172,7 @@ top_p_component = gr.Slider(
|
|
180 |
"the next token (using temperature). "
|
181 |
))
|
182 |
|
183 |
-
user_inputs = [text_prompt_component,
|
184 |
-
chatbot_component
|
185 |
-
]
|
186 |
|
187 |
bot_inputs = [
|
188 |
google_key_component,
|
@@ -204,7 +194,6 @@ with gr.Blocks() as demo:
|
|
204 |
google_key_component.render()
|
205 |
with gr.Row():
|
206 |
video_prompt_component.render()
|
207 |
-
|
208 |
chatbot_component.render()
|
209 |
text_prompt_component.render()
|
210 |
run_button_component.render()
|
@@ -236,62 +225,60 @@ with gr.Blocks() as demo:
|
|
236 |
)
|
237 |
|
238 |
gr.Examples(
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
[
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
"Give me some tips to improve my deadlift.",
|
255 |
-
[("", "")]
|
256 |
-
],
|
257 |
-
[
|
258 |
-
"",
|
259 |
-
"gemini-1.5-pro-latest",
|
260 |
-
"./example2.mp4",
|
261 |
-
.7,
|
262 |
-
1024,
|
263 |
-
"",
|
264 |
-
32,
|
265 |
-
1,
|
266 |
-
"How is my form?",
|
267 |
-
[("", "")]
|
268 |
-
],
|
269 |
-
[
|
270 |
-
"",
|
271 |
-
"gemini-1.5-pro-latest",
|
272 |
-
"./example3.mp4",
|
273 |
-
.7,
|
274 |
-
1024,
|
275 |
-
"",
|
276 |
-
32,
|
277 |
-
1,
|
278 |
-
"What improvements can I make?",
|
279 |
-
[("", "")]
|
280 |
-
],
|
281 |
-
[
|
282 |
-
"",
|
283 |
-
"gemini-1.5-pro-latest",
|
284 |
-
"./example4.mp4",
|
285 |
-
.7,
|
286 |
-
1024,
|
287 |
-
"",
|
288 |
-
32,
|
289 |
-
1,
|
290 |
-
"I just started working out. I'm not sure I'm doing it right. Can you check?",
|
291 |
-
[("", "")]
|
292 |
-
]
|
293 |
],
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
demo.queue(max_size=99).launch(debug=False, show_error=True)
|
|
|
1 |
import os
|
2 |
import time
|
3 |
from typing import List, Tuple, Optional
|
|
|
|
|
4 |
import google.generativeai as genai
|
5 |
import gradio as gr
|
|
|
|
|
6 |
|
7 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
8 |
|
|
|
17 |
Pacing and Timing: Evaluate the pacing and timing of the exercises. Suggest any adjustments needed to optimize performance.
|
18 |
Overall Performance: Give an overall assessment of the workout, highlighting strengths and areas for improvement.
|
19 |
Remember to be encouraging and supportive in your feedback. Your goal is to help them improve and stay motivated. Thank you!
|
20 |
+
"""
|
|
|
|
|
|
|
21 |
|
22 |
def preprocess_stop_sequences(stop_sequences: str) -> Optional[List[str]]:
|
23 |
if not stop_sequences:
|
|
|
66 |
video_file = genai.get_file(video_file.name)
|
67 |
|
68 |
if video_file.state.name == "FAILED":
|
69 |
+
raise ValueError(video_file.state.name)
|
70 |
|
71 |
response = model.generate_content(
|
72 |
contents=[video_file, combined_prompt],
|
|
|
82 |
generation_config=generation_config)
|
83 |
response.resolve()
|
84 |
|
|
|
85 |
# streaming effect
|
86 |
chatbot[-1][1] = ""
|
87 |
for chunk in response:
|
|
|
172 |
"the next token (using temperature). "
|
173 |
))
|
174 |
|
175 |
+
user_inputs = [text_prompt_component, chatbot_component]
|
|
|
|
|
176 |
|
177 |
bot_inputs = [
|
178 |
google_key_component,
|
|
|
194 |
google_key_component.render()
|
195 |
with gr.Row():
|
196 |
video_prompt_component.render()
|
|
|
197 |
chatbot_component.render()
|
198 |
text_prompt_component.render()
|
199 |
run_button_component.render()
|
|
|
225 |
)
|
226 |
|
227 |
gr.Examples(
|
228 |
+
fn=bot,
|
229 |
+
inputs=bot_inputs,
|
230 |
+
outputs=[chatbot_component],
|
231 |
+
examples=[
|
232 |
[
|
233 |
+
"",
|
234 |
+
"gemini-1.5-pro-latest",
|
235 |
+
"./example1.mp4",
|
236 |
+
.7,
|
237 |
+
1024,
|
238 |
+
"",
|
239 |
+
32,
|
240 |
+
1,
|
241 |
+
"Give me some tips to improve my deadlift.",
|
242 |
+
[("", "")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
],
|
244 |
+
[
|
245 |
+
"",
|
246 |
+
"gemini-1.5-pro-latest",
|
247 |
+
"./example2.mp4",
|
248 |
+
.7,
|
249 |
+
1024,
|
250 |
+
"",
|
251 |
+
32,
|
252 |
+
1,
|
253 |
+
"How is my form?",
|
254 |
+
[("", "")]
|
255 |
+
],
|
256 |
+
[
|
257 |
+
"",
|
258 |
+
"gemini-1.5-pro-latest",
|
259 |
+
"./example3.mp4",
|
260 |
+
.7,
|
261 |
+
1024,
|
262 |
+
"",
|
263 |
+
32,
|
264 |
+
1,
|
265 |
+
"What improvements can I make?",
|
266 |
+
[("", "")]
|
267 |
+
],
|
268 |
+
[
|
269 |
+
"",
|
270 |
+
"gemini-1.5-pro-latest",
|
271 |
+
"./example4.mp4",
|
272 |
+
.7,
|
273 |
+
1024,
|
274 |
+
"",
|
275 |
+
32,
|
276 |
+
1,
|
277 |
+
"I just started working out. I'm not sure I'm doing it right. Can you check?",
|
278 |
+
[("", "")]
|
279 |
+
]
|
280 |
+
],
|
281 |
+
#cache_examples="lazy",
|
282 |
+
)
|
283 |
|
284 |
demo.queue(max_size=99).launch(debug=False, show_error=True)
|