Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,16 @@ import gradio as gr
|
|
2 |
import re
|
3 |
|
4 |
# Функция для анализа поста
|
5 |
-
def analyze_post(description,
|
6 |
-
#
|
7 |
-
total_likes = int(
|
8 |
-
total_comments = int(
|
9 |
-
total_likes_on_comments = int(
|
10 |
|
11 |
# Расчет средней вовлеченности
|
12 |
avg_likes_per_comment = total_likes_on_comments / total_comments if total_comments > 0 else 0
|
13 |
|
14 |
-
#
|
15 |
pattern = r"Фото профиля (\S+)\n(.+?)\n\d+ (?:ч|дн)\.(?:\"Нравится\": (\d+))?(?:Ответить)?"
|
16 |
matches = re.findall(pattern, all_comments)
|
17 |
|
@@ -27,10 +27,14 @@ def analyze_post(description, likes, comments, likes_on_comments, all_comments):
|
|
27 |
|
28 |
# Итоговый вывод
|
29 |
result = (
|
30 |
-
f"
|
31 |
-
f"
|
32 |
-
f"
|
33 |
-
f"
|
|
|
|
|
|
|
|
|
34 |
)
|
35 |
|
36 |
return result, users_output, comments_output, likes_chronology_output, total_likes_sum
|
@@ -39,11 +43,15 @@ def analyze_post(description, likes, comments, likes_on_comments, all_comments):
|
|
39 |
iface = gr.Interface(
|
40 |
fn=analyze_post,
|
41 |
inputs=[
|
42 |
-
gr.
|
43 |
-
gr.
|
44 |
-
gr.Number(label="
|
45 |
-
gr.
|
46 |
-
gr.Textbox(label="
|
|
|
|
|
|
|
|
|
47 |
],
|
48 |
outputs=["text", "text", "text", "text", "number"],
|
49 |
title="Анализ Instagram-поста",
|
|
|
2 |
import re
|
3 |
|
4 |
# Функция для анализа поста
|
5 |
+
def analyze_post(content_type, link_to_post, post_likes, post_date, description, comments_likes, comments_count, total_comments_likes, all_comments):
|
6 |
+
# Анализ общей информации поста
|
7 |
+
total_likes = int(post_likes)
|
8 |
+
total_comments = int(comments_count)
|
9 |
+
total_likes_on_comments = int(total_comments_likes)
|
10 |
|
11 |
# Расчет средней вовлеченности
|
12 |
avg_likes_per_comment = total_likes_on_comments / total_comments if total_comments > 0 else 0
|
13 |
|
14 |
+
# Паттерн для извлечения никнейма, комментария и лайков
|
15 |
pattern = r"Фото профиля (\S+)\n(.+?)\n\d+ (?:ч|дн)\.(?:\"Нравится\": (\d+))?(?:Ответить)?"
|
16 |
matches = re.findall(pattern, all_comments)
|
17 |
|
|
|
27 |
|
28 |
# Итоговый вывод
|
29 |
result = (
|
30 |
+
f"Content Type: {content_type}\n"
|
31 |
+
f"Link to Post: {link_to_post}\n"
|
32 |
+
f"Post Information\n"
|
33 |
+
f"Likes: {total_likes}\n"
|
34 |
+
f"Post Date: {post_date}\n"
|
35 |
+
f"Description: {description}\n\n"
|
36 |
+
f"Total Comments: {total_comments}\n"
|
37 |
+
f"Average Likes per Comment: {avg_likes_per_comment:.2f}\n"
|
38 |
)
|
39 |
|
40 |
return result, users_output, comments_output, likes_chronology_output, total_likes_sum
|
|
|
43 |
iface = gr.Interface(
|
44 |
fn=analyze_post,
|
45 |
inputs=[
|
46 |
+
gr.Radio(["Photo", "Video"], label="Content Type"), # Выбор типа контента
|
47 |
+
gr.Textbox(label="Link to Post", placeholder="Введите ссылку на пост"), # Ссылка на пост
|
48 |
+
gr.Number(label="Likes", placeholder="Введите количество лайков на посте"), # Лайки на посте
|
49 |
+
gr.Textbox(label="Post Date", placeholder="Введите дату публикации"), # Дата публикации
|
50 |
+
gr.Textbox(label="Description", placeholder="Введите описание поста"), # Описание поста
|
51 |
+
gr.Number(label="Количество лайков на комментарии"), # Количество лайков на комментариях
|
52 |
+
gr.Number(label="Количество комментариев"), # Количество комментариев
|
53 |
+
gr.Number(label="Общее количество лайков на комментариях"), # Общая сумма лайков на комментариях
|
54 |
+
gr.Textbox(label="Все комментарии", placeholder="Введите комментарии в формате, как указано в примере") # Все комментарии
|
55 |
],
|
56 |
outputs=["text", "text", "text", "text", "number"],
|
57 |
title="Анализ Instagram-поста",
|