Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,14 +15,30 @@ def process_video_and_questions(video, sitting, hands, location, screen):
|
|
15 |
# Construct the query with the video name included
|
16 |
query = f"Answer the questions from the video\n"
|
17 |
additional_info = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
if sitting:
|
19 |
additional_info.append("Is the subject in the video standing or sitting?")
|
|
|
|
|
20 |
if hands:
|
21 |
additional_info.append("Is the subject holding any object in their hands, if so the hands are not free else they are free?")
|
|
|
|
|
22 |
if location:
|
23 |
additional_info.append("Is the subject present indoors or outdoors?")
|
|
|
|
|
24 |
if screen:
|
25 |
additional_info.append("Is the subject interacting with a screen in the background by facing the screen?")
|
|
|
26 |
|
27 |
end_query = """Provide the results in <annotation> tags, where 0 indicates False, 1 indicates True, and None indicates that no information is present. Follow the below examples\n:
|
28 |
<annotation>indoors: 0</annotation>
|
@@ -36,56 +52,21 @@ def process_video_and_questions(video, sitting, hands, location, screen):
|
|
36 |
|
37 |
# Assuming your describe_video function handles the video processing
|
38 |
response = describe_video(video, final_prompt)
|
39 |
-
final_response = f"<video_name>{video_name}</video_name>" + " " + response
|
40 |
-
return final_response
|
41 |
-
|
42 |
-
|
43 |
-
# def process_video_and_questions(video, sitting, hands, location, screen):
|
44 |
-
# # Extract the video name (filename)
|
45 |
-
# video_name = os.path.basename(video)
|
46 |
|
47 |
-
#
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
#
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
# additional_info.append("<annotation>standing: None</annotation>")
|
56 |
-
|
57 |
-
# if hands is not None:
|
58 |
-
# additional_info.append("Is the subject holding any object in their hands, if so the hands are not free else they are free?")
|
59 |
-
# else:
|
60 |
-
# additional_info.append("<annotation>hands.free: None</annotation>")
|
61 |
-
|
62 |
-
# if location is not None:
|
63 |
-
# additional_info.append("Is the subject present indoors or outdoors?")
|
64 |
-
# else:
|
65 |
-
# additional_info.append("<annotation>indoors: None</annotation>")
|
66 |
-
|
67 |
-
# if screen is not None:
|
68 |
-
# additional_info.append("Is the subject interacting with a screen in the background by facing the screen?")
|
69 |
-
# else:
|
70 |
-
# additional_info.append("<annotation>screen.interaction_yes: None</annotation>")
|
71 |
-
|
72 |
-
# # Updated end_query with structured prompt
|
73 |
-
# end_query = """
|
74 |
-
# You're an AI assistant, and your goal is to provide the results of the video analysis in the correct format as described below:
|
75 |
|
76 |
-
|
77 |
-
# - Provide the results in <annotation> tags, where 0 indicates False, 1 indicates True, and None indicates that no information is present.
|
78 |
-
# - Use <annotation> tags for each attribute like indoors, standing, hands.free, and screen.interaction_yes.
|
79 |
-
# </annotations>
|
80 |
-
# """
|
81 |
-
|
82 |
-
# final_query = query + " " + " ".join(additional_info)
|
83 |
-
# final_prompt = final_query + " " + end_query
|
84 |
-
|
85 |
-
# # Assuming your describe_video function handles the video processing
|
86 |
-
# response = describe_video(video, final_prompt)
|
87 |
-
# final_response = f"<video_name>{video_name}</video_name>" + " " + response
|
88 |
-
# return final_response
|
89 |
|
90 |
|
91 |
def output_to_csv(final_response):
|
|
|
15 |
# Construct the query with the video name included
|
16 |
query = f"Answer the questions from the video\n"
|
17 |
additional_info = []
|
18 |
+
|
19 |
+
# Initialize placeholders for annotations with None by default
|
20 |
+
annotations = {
|
21 |
+
"indoors": None,
|
22 |
+
"standing": None,
|
23 |
+
"hands.free": None,
|
24 |
+
"screen.interaction_yes": None
|
25 |
+
}
|
26 |
+
|
27 |
if sitting:
|
28 |
additional_info.append("Is the subject in the video standing or sitting?")
|
29 |
+
annotations["standing"] = 0 # Default value if selected
|
30 |
+
|
31 |
if hands:
|
32 |
additional_info.append("Is the subject holding any object in their hands, if so the hands are not free else they are free?")
|
33 |
+
annotations["hands.free"] = 0 # Default value if selected
|
34 |
+
|
35 |
if location:
|
36 |
additional_info.append("Is the subject present indoors or outdoors?")
|
37 |
+
annotations["indoors"] = 0 # Default value if selected
|
38 |
+
|
39 |
if screen:
|
40 |
additional_info.append("Is the subject interacting with a screen in the background by facing the screen?")
|
41 |
+
annotations["screen.interaction_yes"] = 0 # Default value if selected
|
42 |
|
43 |
end_query = """Provide the results in <annotation> tags, where 0 indicates False, 1 indicates True, and None indicates that no information is present. Follow the below examples\n:
|
44 |
<annotation>indoors: 0</annotation>
|
|
|
52 |
|
53 |
# Assuming your describe_video function handles the video processing
|
54 |
response = describe_video(video, final_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
# Parse the response and update the corresponding annotations
|
57 |
+
for line in response.split('\n'):
|
58 |
+
if '<annotation>' in line:
|
59 |
+
key_value = line.replace('<annotation>', '').replace('</annotation>', '').strip().split(': ')
|
60 |
+
if len(key_value) == 2:
|
61 |
+
key, value = key_value
|
62 |
+
annotations[key] = value
|
63 |
|
64 |
+
# Construct the final response with all annotations
|
65 |
+
final_response = f"<video_name>{video_name}</video_name>\n"
|
66 |
+
for key, value in annotations.items():
|
67 |
+
final_response += f"<annotation>{key}: {value}</annotation>\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
+
return final_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
|
72 |
def output_to_csv(final_response):
|