Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from datetime import datetime
|
|
| 5 |
|
| 6 |
sentiment_pipe = pipeline('sentiment-analysis',model='distilbert-base-uncased-finetuned-sst-2-english')
|
| 7 |
|
| 8 |
-
summarizer_pipe = pipeline('text-generation', model='sshleifer/distilbart-cnn-12-6')
|
| 9 |
|
| 10 |
def format_sentiment_result(label, score):
|
| 11 |
|
|
@@ -98,6 +97,7 @@ def clear_all():
|
|
| 98 |
''
|
| 99 |
)
|
| 100 |
|
|
|
|
| 101 |
def analyze_with_history_and_stats(text, history):
|
| 102 |
"""
|
| 103 |
Повертає 4 значення: html_card, history, DataFrame, stats_markdown.
|
|
@@ -126,27 +126,30 @@ def analyze_with_history_and_stats(text, history):
|
|
| 126 |
|
| 127 |
def get_stats(history):
|
| 128 |
"""Повертає Markdown-рядок зі статистикою сесії."""
|
| 129 |
-
|
| 130 |
if not history:
|
| 131 |
-
return
|
| 132 |
|
| 133 |
total = len(history)
|
| 134 |
-
|
| 135 |
-
pos = sum(1 for h in history if h["Результат"] == "POSITIVE")
|
| 136 |
neg = total - pos
|
| 137 |
-
|
| 138 |
pct_p = pos / total * 100
|
| 139 |
pct_n = neg / total * 100
|
| 140 |
-
|
| 141 |
longest = max(history, key=lambda h: len(h["Текст"].split()))
|
|
|
|
| 142 |
longest_words = len(longest["Текст"].split())
|
| 143 |
|
| 144 |
-
|
|
|
|
|
|
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
last_time = max(times).strftime("%H:%M:%S")
|
| 150 |
|
| 151 |
return (
|
| 152 |
f'📊 **Статистика сесії**\n\n'
|
|
@@ -154,10 +157,9 @@ def get_stats(history):
|
|
| 154 |
f'Позитивних: **{pos}** ({pct_p:.0f}%) | '
|
| 155 |
f'Негативних: **{neg}** ({pct_n:.0f}%)'
|
| 156 |
f'Найдовший текст: **{longest_words} слів**\n | '
|
| 157 |
-
f'Середня впевненість: **{avg_conf:.2f}**\n | '
|
| 158 |
f'Перша сесія: **{first_time}**\n | '
|
| 159 |
f'Остання сесія: **{last_time}** | '
|
| 160 |
-
|
| 161 |
|
| 162 |
def save_to_wishlist(text, wishlist):
|
| 163 |
if not text.strip():
|
|
@@ -170,7 +172,8 @@ def save_to_wishlist(text, wishlist):
|
|
| 170 |
for i, item in enumerate(wishlist)
|
| 171 |
)
|
| 172 |
|
| 173 |
-
with gr.Blocks(title='NLP Analytics Dashboard'
|
|
|
|
| 174 |
|
| 175 |
gr.Markdown('# NLP Analytics Dashboard')
|
| 176 |
gr.Markdown('Аналізуй текст, накопичуй статистику, порівнюй результати.')
|
|
|
|
| 5 |
|
| 6 |
sentiment_pipe = pipeline('sentiment-analysis',model='distilbert-base-uncased-finetuned-sst-2-english')
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
def format_sentiment_result(label, score):
|
| 10 |
|
|
|
|
| 97 |
''
|
| 98 |
)
|
| 99 |
|
| 100 |
+
|
| 101 |
def analyze_with_history_and_stats(text, history):
|
| 102 |
"""
|
| 103 |
Повертає 4 значення: html_card, history, DataFrame, stats_markdown.
|
|
|
|
| 126 |
|
| 127 |
def get_stats(history):
|
| 128 |
"""Повертає Markdown-рядок зі статистикою сесії."""
|
|
|
|
| 129 |
if not history:
|
| 130 |
+
return '📊 **Статистика сесії:** немає даних'
|
| 131 |
|
| 132 |
total = len(history)
|
| 133 |
+
pos = sum(1 for h in history if h['Результат'] == 'POSITIVE')
|
|
|
|
| 134 |
neg = total - pos
|
|
|
|
| 135 |
pct_p = pos / total * 100
|
| 136 |
pct_n = neg / total * 100
|
|
|
|
| 137 |
longest = max(history, key=lambda h: len(h["Текст"].split()))
|
| 138 |
+
|
| 139 |
longest_words = len(longest["Текст"].split())
|
| 140 |
|
| 141 |
+
times = [h["Час"] for h in history]
|
| 142 |
+
|
| 143 |
+
from datetime import datetime
|
| 144 |
|
| 145 |
+
times = []
|
| 146 |
+
for h in history:
|
| 147 |
+
t = h.get("Час")
|
| 148 |
+
if isinstance(t, datetime):
|
| 149 |
+
times.append(t)
|
| 150 |
|
| 151 |
+
first_time = min(times).strftime("%H:%M:%S") if times else "N/A"
|
| 152 |
+
last_time = max(times).strftime("%H:%M:%S") if times else "N/A"
|
|
|
|
| 153 |
|
| 154 |
return (
|
| 155 |
f'📊 **Статистика сесії**\n\n'
|
|
|
|
| 157 |
f'Позитивних: **{pos}** ({pct_p:.0f}%) | '
|
| 158 |
f'Негативних: **{neg}** ({pct_n:.0f}%)'
|
| 159 |
f'Найдовший текст: **{longest_words} слів**\n | '
|
|
|
|
| 160 |
f'Перша сесія: **{first_time}**\n | '
|
| 161 |
f'Остання сесія: **{last_time}** | '
|
| 162 |
+
)
|
| 163 |
|
| 164 |
def save_to_wishlist(text, wishlist):
|
| 165 |
if not text.strip():
|
|
|
|
| 172 |
for i, item in enumerate(wishlist)
|
| 173 |
)
|
| 174 |
|
| 175 |
+
with gr.Blocks(title='NLP Analytics Dashboard', theme=gr.themes.Glass(),
|
| 176 |
+
) as demo:
|
| 177 |
|
| 178 |
gr.Markdown('# NLP Analytics Dashboard')
|
| 179 |
gr.Markdown('Аналізуй текст, накопичуй статистику, порівнюй результати.')
|