Update app.py
Browse files
app.py
CHANGED
@@ -98,13 +98,26 @@ def extract_frames(text):
|
|
98 |
logging.error(f"Groq API error: {e}")
|
99 |
return extract_frames_fallback(text)
|
100 |
|
101 |
-
# Fallback method for frame extraction
|
102 |
def extract_frames_fallback(text):
|
103 |
detected_frames = set()
|
|
|
104 |
text_lower = text.lower()
|
|
|
105 |
for category, keywords in frame_categories.items():
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
return list(detected_frames)
|
109 |
|
110 |
# Extract captions from DOCX
|
@@ -136,6 +149,7 @@ def extract_metadata_from_excel(excel_file):
|
|
136 |
"Number of Audios": row.get("Number of Audios", 0),
|
137 |
"Likes": row.get("Likes", 0),
|
138 |
"Comments": row.get("Comments", 0),
|
|
|
139 |
}
|
140 |
extracted_data.append(post_data)
|
141 |
|
|
|
98 |
logging.error(f"Groq API error: {e}")
|
99 |
return extract_frames_fallback(text)
|
100 |
|
101 |
+
# Fallback method for frame extraction (with categorization of Major, Significant, Minor)
|
102 |
def extract_frames_fallback(text):
|
103 |
detected_frames = set()
|
104 |
+
frame_focus = {"Major Focus": [], "Significant Focus": [], "Minor Mention": []}
|
105 |
text_lower = text.lower()
|
106 |
+
|
107 |
for category, keywords in frame_categories.items():
|
108 |
+
keyword_count = sum(word in text_lower for word in keywords)
|
109 |
+
if keyword_count > 5:
|
110 |
+
frame_focus["Major Focus"].append(category)
|
111 |
+
elif keyword_count > 2:
|
112 |
+
frame_focus["Significant Focus"].append(category)
|
113 |
+
elif keyword_count > 0:
|
114 |
+
frame_focus["Minor Mention"].append(category)
|
115 |
+
|
116 |
+
# Return categorized frames
|
117 |
+
for focus, categories in frame_focus.items():
|
118 |
+
for category in categories:
|
119 |
+
detected_frames.add(f"{focus}: {category}")
|
120 |
+
|
121 |
return list(detected_frames)
|
122 |
|
123 |
# Extract captions from DOCX
|
|
|
149 |
"Number of Audios": row.get("Number of Audios", 0),
|
150 |
"Likes": row.get("Likes", 0),
|
151 |
"Comments": row.get("Comments", 0),
|
152 |
+
"Tagged Audience": row.get("Tagged Audience", "No"),
|
153 |
}
|
154 |
extracted_data.append(post_data)
|
155 |
|