|
import gradio as gr |
|
import re |
|
|
|
|
|
def analyze_post(content_type, link_to_post, post_likes, post_date, description, comment_count, all_comments): |
|
|
|
pattern = r"Фото профиля (\S+)\n(.+?)\n\d+ (?:ч|дн)\.(?:\"Нравится\": (\d+))?(?:Ответить)?" |
|
matches = re.findall(pattern, all_comments) |
|
|
|
|
|
usernames_output = "\n".join([match[0] for match in matches]) |
|
comments_output = "\n".join([match[1] for match in matches]) |
|
|
|
|
|
likes_chronology_output = "\n".join([match[2] if match[2] else "0" for match in matches]) |
|
|
|
|
|
total_likes_sum = sum(int(match[2]) for match in matches if match[2]) |
|
|
|
|
|
post_summary = ( |
|
f"Content Type: {content_type}\n" |
|
f"Link to Post: {link_to_post}\n" |
|
f"Post Information\n" |
|
f"Likes: {post_likes}\n" |
|
f"Post Date: {post_date}\n" |
|
f"Description: {description}\n" |
|
f"Total Comments (Expected): {comment_count}\n" |
|
f"Extracted Comments: {len(matches)}\n" |
|
f"Total Likes on Comments: {total_likes_sum}\n" |
|
) |
|
|
|
return post_summary, usernames_output, comments_output, likes_chronology_output, total_likes_sum |
|
|
|
|
|
iface = gr.Interface( |
|
fn=analyze_post, |
|
inputs=[ |
|
gr.Radio(["Photo", "Video"], label="Content Type"), |
|
gr.Textbox(label="Link to Post", placeholder="Введите ссылку на пост"), |
|
gr.Number(label="Likes"), |
|
gr.Textbox(label="Post Date", placeholder="Введите дату публикации"), |
|
gr.Textbox(label="Description", placeholder="Введите описание поста"), |
|
gr.Number(label="Total Comment Count"), |
|
gr.Textbox(label="All Comments", placeholder="Введите комментарии в формате, как указано в примере") |
|
], |
|
outputs=[ |
|
gr.Textbox(label="Post Summary"), |
|
gr.Textbox(label="Usernames (Output 1)"), |
|
gr.Textbox(label="Comments (Output 2)"), |
|
gr.Textbox(label="Likes Chronology (Output 3)"), |
|
gr.Textbox(label="Total Likes on Comments (Output 4)") |
|
], |
|
title="Instagram Comment Analyzer", |
|
description="Analyze comments for a specific Instagram post." |
|
) |
|
|
|
iface.launch() |