Download app.py from aysan98/Monthly: direct link, hf CLI and curl.
- Browser
- Download file 50.8 kB
-
https://huggingface.co/spaces/aysan98/Monthly/resolve/main/app.py
- Command line
-
hf download hf://spaces/aysan98/Monthly/app.py
-
curl -L -o app.py https://huggingface.co/spaces/aysan98/Monthly/resolve/main/app.py
50.8 kB
| import gradio as gr | |
| import pandas as pd | |
| import numpy as np | |
| import warnings | |
| import plotly.graph_objects as go | |
| import plotly.io as pio | |
| from xhtml2pdf import pisa | |
| warnings.filterwarnings('ignore') | |
| # ───────────────────────────────────────────── | |
| # توابع کمکی | |
| # ───────────────────────────────────────────── | |
| def extract_service_name(service_text): | |
| """استخراج نام سرویس و زیرسرویس (قبل و بعد از علامت >)""" | |
| if pd.isna(service_text): | |
| return 'نامشخص', 'نامشخص' | |
| service_str = str(service_text).strip() | |
| separators = ['>', '>', '›', '>', ' > ', '<', '<', '‹', '<', ' < '] | |
| for sep in separators: | |
| if sep in service_str: | |
| parts = service_str.split(sep) | |
| main_service = parts[0].strip() | |
| sub_service = parts[1].strip() if len(parts) > 1 else 'نامشخص' | |
| return main_service, sub_service | |
| return service_str, 'ندارد' | |
| def categorize_service(main_service, sub_service, site_value): | |
| """دستهبندی سرویسها""" | |
| service_lower = str(main_service).lower().strip() | |
| # چندرسانهای: عکس، ویدئو، گرافیک، صوت — زیرسرویسها جداگانه نگه داشته میشوند | |
| multimedia_keywords = ['عکس', 'ویدئو', 'ویدیو', 'گرافیک', 'صوت'] | |
| if any(keyword in service_lower for keyword in multimedia_keywords): | |
| media_type = next(k for k in multimedia_keywords if k in service_lower) | |
| return 'چندرسانهای', media_type | |
| # استانها: هر سرویسی که شامل کلمه «استان» باشد → یک دسته واحد | |
| if 'استان' in service_lower: | |
| return 'استانها', sub_service | |
| # زبانهای خارجی: سایت ایسنا نباشد | |
| site_str = str(site_value).lower().strip() | |
| if 'ایسنا' not in site_str and site_str != 'nan': | |
| final_sub = main_service if sub_service == 'ندارد' else sub_service | |
| return 'زبانهای خارجی', final_sub | |
| return main_service, sub_service | |
| def categorize_for_isna_table(row): | |
| """دستهبندی اخبار برای جدول کل ایسنا""" | |
| service_str = str(row['سرویس_نهایی']).lower().strip() | |
| site_str = str(row.get('سایت', '')).lower().strip() | |
| if 'بازار' in service_str: | |
| return 'بازار' | |
| if 'ایسنا' in service_str and '+' in service_str: | |
| return 'ایسنا+' | |
| if 'ایسنا' not in site_str and site_str != 'nan' and site_str != '': | |
| return 'زبانهای خارجی' | |
| if 'استان' in service_str: | |
| return 'استانها' | |
| return 'تهران' | |
| def custom_round(value): | |
| """گرد کردن سفارشی""" | |
| if value - int(value) < 0.5: | |
| return int(value) | |
| else: | |
| return int(value) + 1 | |
| def extract_date_only(datetime_str): | |
| """استخراج فقط تاریخ از تاریخ و زمان""" | |
| if pd.isna(datetime_str): | |
| return 'نامشخص' | |
| try: | |
| date_str = str(datetime_str) | |
| if hasattr(datetime_str, 'strftime'): | |
| return datetime_str.strftime('%Y/%m/%d') | |
| if ' ' in date_str: | |
| return date_str.split(' ')[0] | |
| return date_str | |
| except: | |
| return str(datetime_str) | |
| # ───────────────────────────────────────────── | |
| # نمودار | |
| # ───────────────────────────────────────────── | |
| def create_traffic_chart(service_stats): | |
| """ایجاد نمودار میلهای stacked با درصدها""" | |
| service_stats_sorted = service_stats.sort_values('تعداد_اخبار_ارسالی', ascending=True).copy() | |
| service_stats_sorted['درصد_اخبار_متوسط'] = ( | |
| 100 - service_stats_sorted['درصد_اخبار_کم_بازدید'] - service_stats_sorted['درصد_اخبار_پربازدید'] | |
| ) | |
| fig = go.Figure() | |
| # FIX: label now says "زیر 200" (strictly less than 200) | |
| fig.add_trace(go.Bar( | |
| y=service_stats_sorted['سرویس'], | |
| x=service_stats_sorted['درصد_اخبار_کم_بازدید'], | |
| name='زیر 200 بازدید', | |
| orientation='h', | |
| marker=dict(color='#ef5350'), | |
| text=[f"{int(p)}%" for p in service_stats_sorted['درصد_اخبار_کم_بازدید']], | |
| textposition='inside', | |
| hovertemplate='<b>%{y}</b><br>زیر 200: %{x}%<extra></extra>' | |
| )) | |
| fig.add_trace(go.Bar( | |
| y=service_stats_sorted['سرویس'], | |
| x=service_stats_sorted['درصد_اخبار_متوسط'], | |
| name='بین 200 تا 1000', | |
| orientation='h', | |
| marker=dict(color='#64b5f6'), | |
| text=[f"{int(p)}%" for p in service_stats_sorted['درصد_اخبار_متوسط']], | |
| textposition='inside', | |
| hovertemplate='<b>%{y}</b><br>200-1000: %{x}%<extra></extra>' | |
| )) | |
| fig.add_trace(go.Bar( | |
| y=service_stats_sorted['سرویس'], | |
| x=service_stats_sorted['درصد_اخبار_پربازدید'], | |
| name='1000 بازدید و بالاتر', | |
| orientation='h', | |
| marker=dict(color='#66bb6a'), | |
| text=[f"{int(p)}%" for p in service_stats_sorted['درصد_اخبار_پربازدید']], | |
| textposition='inside', | |
| hovertemplate='<b>%{y}</b><br>1000 و بالاتر: %{x}%<extra></extra>' | |
| )) | |
| fig.update_layout( | |
| title={ | |
| 'text': 'نمودار توزیع درصد بازدید اخبار به تفکیک سرویسها', | |
| 'font': {'size': 19, 'family': 'Tahoma', 'color': '#1976d2'}, | |
| 'x': 0.5, 'xanchor': 'center' | |
| }, | |
| barmode='stack', | |
| xaxis_title='درصد', | |
| yaxis_title='سرویس', | |
| font=dict(family='Tahoma', size=14), | |
| height=max(500, len(service_stats_sorted) * 50), | |
| legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="center", x=0.5, font=dict(size=15)), | |
| plot_bgcolor='rgba(240,240,240,0.5)', | |
| hovermode='closest', | |
| margin=dict(l=150, r=50, t=100, b=80), | |
| xaxis=dict(range=[0, 100]) | |
| ) | |
| fig.update_xaxes(gridcolor='rgba(200,200,200,0.3)') | |
| fig.update_yaxes(gridcolor='rgba(200,200,200,0.3)') | |
| return fig | |
| # ───────────────────────────────────────────── | |
| # ───────────────────────────────────────────── | |
| def html_to_pdf(html_string, pdf_filename): | |
| with open(pdf_filename, "wb") as pdf_file: | |
| pisa.CreatePDF(html_string, dest=pdf_file) | |
| # ───────────────────────────────────────────── | |
| # پردازش اصلی | |
| # ───────────────────────────────────────────── | |
| def process_news_data(file): | |
| try: | |
| excel_file = pd.ExcelFile(file) | |
| sheet_names = excel_file.sheet_names | |
| sheet_name = 'کلی' if 'کلی' in sheet_names else sheet_names[0] | |
| df_test = pd.read_excel(file, sheet_name=sheet_name, header=None, nrows=5) | |
| header_row = 0 | |
| for i, row in df_test.iterrows(): | |
| if 'تیتر' in str(row.values) or 'ناشر' in str(row.values) or 'بازدید' in str(row.values): | |
| header_row = i | |
| break | |
| df = pd.read_excel(file, sheet_name=sheet_name, header=header_row) | |
| required_columns = ['بازدید', 'تیتر', 'سرویس'] | |
| missing_columns = [col for col in required_columns if col not in df.columns] | |
| if missing_columns: | |
| return None, f""" | |
| <div style='text-align:right;direction:rtl;font-family:Tahoma;padding:20px;'> | |
| <h3>❌ ستونهای مورد نیاز یافت نشد</h3> | |
| <p><strong>ستونهای مفقود:</strong> {', '.join(missing_columns)}</p> | |
| <p><strong>ستونهای موجود:</strong> {', '.join(list(df.columns))}</p> | |
| </div>""", None, None | |
| # پاکسازی | |
| df_clean = df.dropna(subset=['بازدید', 'تیتر']).copy() | |
| df_clean['بازدید'] = pd.to_numeric(df_clean['بازدید'], errors='coerce') | |
| df_clean = df_clean[df_clean['بازدید'] >= 0] | |
| # سرویسها | |
| df_clean[['سرویس_اصلی', 'زیرسرویس']] = df_clean['سرویس'].apply( | |
| lambda x: pd.Series(extract_service_name(x)) | |
| ) | |
| if 'سایت' in df_clean.columns: | |
| df_clean[['سرویس_نهایی', 'زیرسرویس_نهایی']] = df_clean.apply( | |
| lambda row: pd.Series(categorize_service(row['سرویس_اصلی'], row['زیرسرویس'], row['سایت'])), axis=1 | |
| ) | |
| else: | |
| df_clean['سرویس_نهایی'] = df_clean['سرویس_اصلی'] | |
| df_clean['زیرسرویس_نهایی'] = df_clean['زیرسرویس'] | |
| df_clean['دسته_ایسنا'] = df_clean.apply(categorize_for_isna_table, axis=1) | |
| publish_date_col = next((c for c in ['تاریخ انتشار', 'تاریخ', 'زمان انتشار'] if c in df_clean.columns), None) | |
| reporter_col = next((c for c in ['نام خبرنگار', 'خبرنگار', 'نویسنده'] if c in df_clean.columns), None) | |
| publisher_col = next((c for c in ['ناشر', 'منتشرکننده'] if c in df_clean.columns), None) | |
| # ══════════════════════════════════════ | |
| # آمار کلی | |
| # ══════════════════════════════════════ | |
| total_news_all = len(df_clean) | |
| high_traffic_count_all = len(df_clean[df_clean['بازدید'] >= 1000]) | |
| # FIX: strictly < 200 (news with exactly 200 views are NOT counted as low-traffic) | |
| low_traffic_count_all = len(df_clean[df_clean['بازدید'] < 200]) | |
| # ══════════════════════════════════════ | |
| # جدول کل ایسنا | |
| # ══════════════════════════════════════ | |
| isna_categories = ['تهران', 'استانها', 'زبانهای خارجی', 'ایسنا+', 'بازار'] | |
| isna_stats_list = [] | |
| for category in isna_categories: | |
| df_cat = df_clean[df_clean['دسته_ایسنا'] == category] | |
| if len(df_cat) > 0: | |
| count = len(df_cat) | |
| high = len(df_cat[df_cat['بازدید'] >= 1000]) | |
| low = len(df_cat[df_cat['بازدید'] < 200]) # FIX | |
| share = custom_round((count / total_news_all * 100) if total_news_all > 0 else 0) | |
| isna_stats_list.append({ | |
| 'شاخصها': category, | |
| 'تعداد_اخبار_ارسالی': count, | |
| 'سهم_از_کل': share, | |
| 'تعداد_اخبار_پربازدید': high, | |
| 'تعداد_اخبار_کم_بازدید': low | |
| }) | |
| isna_stats_list.append({ | |
| 'شاخصها': 'جمع کل', | |
| 'تعداد_اخبار_ارسالی': total_news_all, | |
| 'سهم_از_کل': 100, | |
| 'تعداد_اخبار_پربازدید': high_traffic_count_all, | |
| 'تعداد_اخبار_کم_بازدید': low_traffic_count_all | |
| }) | |
| isna_table = pd.DataFrame(isna_stats_list) | |
| # ══════════════════════════════════════ | |
| # آمار تفصیلی سرویسها | |
| # ══════════════════════════════════════ | |
| df_services = df_clean[ | |
| ~df_clean['سرویس_نهایی'].str.contains('ایسنا[+]|بازار|زبان', case=False, na=False) | |
| ] | |
| service_stats = df_services.groupby('سرویس_نهایی').agg( | |
| تعداد_اخبار_ارسالی=('بازدید','count'), | |
| مجموع_بازدید=('بازدید','sum'), | |
| میانگین_بازدید=('بازدید','mean') | |
| ) | |
| service_stats['میانگین_بازدید'] = service_stats['میانگین_بازدید'].round(0).astype(int) | |
| high_by_service = df_services[df_services['بازدید'] >= 1000].groupby('سرویس_نهایی').size() | |
| service_stats['تعداد_اخبار_پربازدید'] = high_by_service.reindex(service_stats.index, fill_value=0).astype(int) | |
| service_stats['درصد_اخبار_پربازدید'] = ( | |
| service_stats['تعداد_اخبار_پربازدید'] / service_stats['تعداد_اخبار_ارسالی'] * 100 | |
| ).apply(custom_round) | |
| low_by_service = df_services[df_services['بازدید'] < 200].groupby('سرویس_نهایی').size() # FIX | |
| service_stats['تعداد_اخبار_کم_بازدید'] = low_by_service.reindex(service_stats.index, fill_value=0).astype(int) | |
| service_stats['درصد_اخبار_کم_بازدید'] = ( | |
| service_stats['تعداد_اخبار_کم_بازدید'] / service_stats['تعداد_اخبار_ارسالی'] * 100 | |
| ).apply(custom_round) | |
| service_stats = service_stats.sort_values('تعداد_اخبار_ارسالی', ascending=False).reset_index() | |
| service_stats = service_stats.rename(columns={'سرویس_نهایی': 'سرویس'}) | |
| # ══════════════════════════════════════ | |
| # نمودار (همه سرویسها) | |
| # ══════════════════════════════════════ | |
| all_service_stats = df_clean.groupby('سرویس_نهایی').agg(تعداد_اخبار_ارسالی=('بازدید','count')) | |
| high_all = df_clean[df_clean['بازدید'] >= 1000].groupby('سرویس_نهایی').size() | |
| all_service_stats['تعداد_اخبار_پربازدید'] = high_all.reindex(all_service_stats.index, fill_value=0).astype(int) | |
| all_service_stats['درصد_اخبار_پربازدید'] = ( | |
| all_service_stats['تعداد_اخبار_پربازدید'] / all_service_stats['تعداد_اخبار_ارسالی'] * 100 | |
| ).apply(custom_round) | |
| low_all = df_clean[df_clean['بازدید'] < 200].groupby('سرویس_نهایی').size() # FIX | |
| all_service_stats['تعداد_اخبار_کم_بازدید'] = low_all.reindex(all_service_stats.index, fill_value=0).astype(int) | |
| all_service_stats['درصد_اخبار_کم_بازدید'] = ( | |
| all_service_stats['تعداد_اخبار_کم_بازدید'] / all_service_stats['تعداد_اخبار_ارسالی'] * 100 | |
| ).apply(custom_round) | |
| all_service_stats = all_service_stats.reset_index().rename(columns={'سرویس_نهایی': 'سرویس'}) | |
| chart = create_traffic_chart(all_service_stats) | |
| # ══════════════════════════════════════ | |
| # 100 خبر پربازدید | |
| # ══════════════════════════════════════ | |
| top_100_cols = ['تیتر', 'زیرسرویس_نهایی', 'بازدید'] | |
| if publish_date_col: top_100_cols.insert(2, publish_date_col) | |
| if reporter_col: top_100_cols.append(reporter_col) | |
| if publisher_col: top_100_cols.append(publisher_col) | |
| top_100_news = df_clean.nlargest(100, 'بازدید')[top_100_cols].copy() | |
| if publish_date_col: | |
| top_100_news['تاریخ_انتشار'] = top_100_news[publish_date_col].apply(extract_date_only) | |
| top_100_news = top_100_news.drop(columns=[publish_date_col]) | |
| rename_map = {'زیرسرویس_نهایی': 'زیرسرویس'} | |
| if reporter_col: rename_map[reporter_col] = 'نام خبرنگار' | |
| if publisher_col: rename_map[publisher_col] = 'ناشر' | |
| top_100_news = top_100_news.rename(columns=rename_map) | |
| # ══════════════════════════════════════ | |
| # میانگین بازدید | |
| # ══════════════════════════════════════ | |
| df_avg = df_clean[ | |
| ~df_clean['سرویس_نهایی'].str.contains('ایسنا[+]|بازار|زبان', case=False, na=False) | |
| ] | |
| avg_stats = df_avg.groupby('سرویس_نهایی').agg( | |
| تعداد_خبر=('بازدید','count'), | |
| مجموع_بازدید=('بازدید','sum'), | |
| میانگین_بازدید=('بازدید','mean') | |
| ) | |
| avg_stats['میانگین_بازدید'] = avg_stats['میانگین_بازدید'].round(0).astype(int) | |
| avg_stats = avg_stats.sort_values('تعداد_خبر', ascending=False).reset_index() | |
| avg_stats = avg_stats.rename(columns={'سرویس_نهایی': 'عنوان_اداره'}) | |
| # ══════════════════════════════════════ | |
| # جدول Word-style: نام اداره | زیرسرویس | ... | |
| # دقیقاً مطابق فرمت فایل ورد ارسالی: | |
| # - استانها: یک ردیف واحد (جمع همه استانها)، نام اداره = "—" | |
| # - چندرسانهای: زیرسرویسها (عکس، ویدئو، گرافیک، صوت) جداگانه | |
| # - سایر سرویسها: زیرسرویسهای مجزا | |
| # ══════════════════════════════════════ | |
| subservice_rows = [] | |
| for service in df_clean['سرویس_نهایی'].unique(): | |
| df_service = df_clean[df_clean['سرویس_نهایی'] == service] | |
| # استانها: همه زیرسرویسها (نام استانها) در یک ردیف جمع میشوند | |
| if 'استان' in str(service).lower(): | |
| count = len(df_service) | |
| high = len(df_service[df_service['بازدید'] >= 1000]) | |
| low = len(df_service[df_service['بازدید'] < 200]) | |
| high_pct = custom_round((high / count * 100) if count > 0 else 0) | |
| low_pct = custom_round((low / count * 100) if count > 0 else 0) | |
| subservice_rows.append({ | |
| 'نام_اداره': '—', | |
| 'زیرسرویس': 'استانها', | |
| 'تعداد_اخبار_ارسالی': count, | |
| 'اخبار_بالای_هزار': high, | |
| 'سهم_پربازدید': high_pct, | |
| 'اخبار_زیر_200': low, | |
| 'سهم_کم_بازدید': low_pct | |
| }) | |
| else: | |
| # سایر سرویسها (از جمله چندرسانهای): زیرسرویسها جداگانه | |
| for subservice in df_service['زیرسرویس_نهایی'].unique(): | |
| df_sub = df_service[df_service['زیرسرویس_نهایی'] == subservice] | |
| count = len(df_sub) | |
| high = len(df_sub[df_sub['بازدید'] >= 1000]) | |
| low = len(df_sub[df_sub['بازدید'] < 200]) | |
| high_pct = custom_round((high / count * 100) if count > 0 else 0) | |
| low_pct = custom_round((low / count * 100) if count > 0 else 0) | |
| subservice_rows.append({ | |
| 'نام_اداره': service, | |
| 'زیرسرویس': subservice, | |
| 'تعداد_اخبار_ارسالی': count, | |
| 'اخبار_بالای_هزار': high, | |
| 'سهم_پربازدید': high_pct, | |
| 'اخبار_زیر_200': low, | |
| 'سهم_کم_بازدید': low_pct | |
| }) | |
| word_style_table = pd.DataFrame(subservice_rows).sort_values( | |
| ['نام_اداره', 'تعداد_اخبار_ارسالی'], ascending=[True, False] | |
| ).reset_index(drop=True) | |
| # ══════════════════════════════════════ | |
| # پربازدیدترین خبر هر اداره | |
| # ══════════════════════════════════════ | |
| top_news_per_service = [] | |
| for service in df_clean['سرویس_نهایی'].unique(): | |
| df_service = df_clean[df_clean['سرویس_نهایی'] == service] | |
| if len(df_service) == 0: | |
| continue | |
| top_row = df_service.nlargest(1, 'بازدید').iloc[0] | |
| entry = { | |
| 'نام_اداره': service, | |
| 'تیتر_خبر': top_row['تیتر'], | |
| 'زیرسرویس': top_row['زیرسرویس_نهایی'], | |
| 'بازدید': int(top_row['بازدید']) | |
| } | |
| if publish_date_col and publish_date_col in top_row.index: | |
| entry['تاریخ_انتشار'] = extract_date_only(top_row[publish_date_col]) | |
| if reporter_col and reporter_col in top_row.index: | |
| entry['نام_خبرنگار'] = top_row[reporter_col] | |
| top_news_per_service.append(entry) | |
| top_news_df = pd.DataFrame(top_news_per_service).sort_values('بازدید', ascending=False).reset_index(drop=True) | |
| # ══════════════════════════════════════ | |
| # ذخیره اکسل | |
| # ══════════════════════════════════════ | |
| output_filename = 'نتایج_تحلیل_ماهانه.xlsx' | |
| with pd.ExcelWriter(output_filename, engine='openpyxl') as writer: | |
| isna_table.to_excel(writer, sheet_name='کل_ایسنا', index=False) | |
| service_stats.to_excel(writer, sheet_name='آمار_تفصیلی_سرویس_ها', index=False) | |
| all_service_stats.to_excel(writer,sheet_name='آمار_همه_سرویس_ها', index=False) | |
| top_100_news.to_excel(writer, sheet_name='100_خبر_پربازدید', index=False) | |
| avg_stats.to_excel(writer, sheet_name='میانگین_بازدید', index=False) | |
| word_style_table.to_excel(writer, sheet_name='جدول_ورد_زیرسرویس_ها', index=False) | |
| top_news_df.to_excel(writer, sheet_name='پربازدیدترین_هر_اداره', index=False) | |
| # آمار کامنت - غیرفعال شده | |
| # if comment_stats is not None: | |
| # comment_stats.to_excel(writer, sheet_name='آمار_کامنت', index=False) | |
| # ══════════════════════════════════════ | |
| # HTML گزارش | |
| # ══════════════════════════════════════ | |
| summary_html = """ | |
| <div style='direction:rtl;font-family:Tahoma,Arial;text-align:right;padding:20px;background-color:white;'> | |
| <h2 style='text-align:center;color:#1976d2;border-bottom:3px solid #1976d2;padding-bottom:10px;'> | |
| گزارش ماهانه عملکرد ایسنا | |
| </h2> | |
| """ | |
| # ── جدول کل ایسنا ────────────────────────────────────────────── | |
| summary_html += """ | |
| <h3 style='color:#388e3c;margin-top:30px;'>📈 آمار کلی</h3> | |
| <h4 style='color:#0d47a1;margin-top:20px;background-color:#e3f2fd;padding:15px;border-radius:8px;'> | |
| 📊 جدول تعداد کل اخبار ارسالی و وضعیت بازدید کل ایسنا | |
| </h4> | |
| <div style='overflow-x:auto;margin:20px 0;'> | |
| <table style='width:100%;border-collapse:collapse;box-shadow:0 2px 8px rgba(0,0,0,.15);font-size:15px;background:#fff;'> | |
| <thead> | |
| <tr style='background:#1976d2;'> | |
| <th style='padding:15px 20px;border:2px solid #1565c0;text-align:right;color:#fff;'>شاخصها</th> | |
| <th style='padding:15px 20px;border:2px solid #1565c0;text-align:right;color:#fff;'>تعداد اخبار ارسالی</th> | |
| <th style='padding:15px 20px;border:2px solid #1565c0;text-align:right;color:#fff;'>سهم از کل</th> | |
| <th style='padding:15px 20px;border:2px solid #1565c0;text-align:right;color:#fff;'>تعداد اخبار پربازدید</th> | |
| <th style='padding:15px 20px;border:2px solid #1565c0;text-align:right;color:#fff;'>تعداد اخبار کمبازدید (زیر 200)</th> | |
| </tr> | |
| </thead><tbody> | |
| """ | |
| for _, row in isna_table.iterrows(): | |
| is_total = row['شاخصها'] == 'جمع کل' | |
| bg = '#1976d2' if is_total else '#e3f2fd' | |
| tc = '#fff' if is_total else '#000' | |
| fw = 'bold' if is_total else 'normal' | |
| bc = '#1565c0' if is_total else '#90caf9' | |
| summary_html += f""" | |
| <tr style='background:{bg};'> | |
| <td style='padding:12px 20px;border:2px solid {bc};text-align:right;font-weight:{fw};color:{tc};'>{row['شاخصها']}</td> | |
| <td style='padding:12px 20px;border:2px solid {bc};text-align:right;font-weight:{fw};color:{tc};'>{int(row['تعداد_اخبار_ارسالی']):,}</td> | |
| <td style='padding:12px 20px;border:2px solid {bc};text-align:right;font-weight:{fw};color:{tc};'>{int(row['سهم_از_کل'])}%</td> | |
| <td style='padding:12px 20px;border:2px solid {bc};text-align:right;font-weight:{fw};color:{tc};'>{int(row['تعداد_اخبار_پربازدید']):,}</td> | |
| <td style='padding:12px 20px;border:2px solid {bc};text-align:right;font-weight:{fw};color:{tc};'>{int(row['تعداد_اخبار_کم_بازدید']):,}</td> | |
| </tr>""" | |
| summary_html += "</tbody></table></div>" | |
| # ── آمار تفصیلی سرویسها ────────────────────────────────────── | |
| tot_cnt = service_stats['تعداد_اخبار_ارسالی'].sum() | |
| tot_high = service_stats['تعداد_اخبار_پربازدید'].sum() | |
| tot_low = service_stats['تعداد_اخبار_کم_بازدید'].sum() | |
| tot_hp = custom_round((tot_high / tot_cnt * 100) if tot_cnt > 0 else 0) | |
| tot_lp = custom_round((tot_low / tot_cnt * 100) if tot_cnt > 0 else 0) | |
| summary_html += """ | |
| <h3 style='color:#7b1fa2;margin-top:30px;'>📋 آمار تفصیلی سرویسها</h3> | |
| <p style='color:#666;font-size:13px;'>(بدون احتساب ایسنا+، بازار و زبانهای خارجی)</p> | |
| <div style='overflow-x:auto;margin:20px 0;'> | |
| <table style='width:100%;border-collapse:collapse;box-shadow:0 2px 4px rgba(0,0,0,.1);font-size:14px;background:#fff;'> | |
| <thead> | |
| <tr style='background:#1976d2;'> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>سرویس</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>تعداد اخبار</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>اخبار پربازدید</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>درصد پربازدید</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>اخبار زیر 200</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>درصد کمبازدید</th> | |
| </tr> | |
| </thead><tbody> | |
| """ | |
| for _, row in service_stats.iterrows(): | |
| summary_html += f""" | |
| <tr style='background:#e3f2fd;'> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;font-weight:bold;color:#000;'>{row['سرویس']}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{int(row['تعداد_اخبار_ارسالی']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#c8e6c9;color:#000;'>{int(row['تعداد_اخبار_پربازدید']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#c8e6c9;color:#000;'>{int(row['درصد_اخبار_پربازدید'])}%</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#ffcdd2;color:#000;'>{int(row['تعداد_اخبار_کم_بازدید']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#ffcdd2;color:#000;'>{int(row['درصد_اخبار_کم_بازدید'])}%</td> | |
| </tr>""" | |
| summary_html += f""" | |
| <tr style='background:#1976d2;'> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>جمع کل</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_cnt):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_high):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_hp)}%</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_low):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_lp)}%</td> | |
| </tr> | |
| </tbody></table></div>""" | |
| # ── جدول Word-style: نام اداره | زیرسرویس ───────────────────── | |
| tot_ws_news = word_style_table['تعداد_اخبار_ارسالی'].sum() | |
| tot_ws_high = word_style_table['اخبار_بالای_هزار'].sum() | |
| tot_ws_low = word_style_table['اخبار_زیر_200'].sum() | |
| tot_ws_hp = custom_round((tot_ws_high / tot_ws_news * 100) if tot_ws_news > 0 else 0) | |
| tot_ws_lp = custom_round((tot_ws_low / tot_ws_news * 100) if tot_ws_news > 0 else 0) | |
| summary_html += """ | |
| <h3 style='color:#d32f2f;margin-top:30px;'>⭐ تعداد اخبار ارسالی زیرسرویسها، پربازدید و کمبازدید</h3> | |
| <p style='color:#666;font-size:13px;'>(بالای 1000 بازدید و زیر 200 بازدید)</p> | |
| <div style='overflow-x:auto;margin:20px 0;'> | |
| <table style='width:100%;border-collapse:collapse;box-shadow:0 2px 4px rgba(0,0,0,.1);font-size:14px;background:#fff;'> | |
| <thead> | |
| <tr style='background:#1976d2;'> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;min-width:110px;'>نام اداره</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;min-width:140px;'>زیر سرویس</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>تعداد اخبار ارسالی</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>اخبار بالای 1000 بازدید</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>سهم پربازدید به کل اخبار (درصد)</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>اخبار زیر 200 بازدید</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>سهم کمبازدید به کل اخبار (درصد)</th> | |
| </tr> | |
| </thead><tbody> | |
| """ | |
| # مرتبسازی سرویسها بر اساس مجموع تعداد اخبار (بزرگتر اول) | |
| service_order = ( | |
| word_style_table.groupby('نام_اداره')['تعداد_اخبار_ارسالی'] | |
| .sum().sort_values(ascending=False).index | |
| ) | |
| current_service = None | |
| for service_name in service_order: | |
| group = word_style_table[word_style_table['نام_اداره'] == service_name] | |
| row_count = len(group) | |
| first_row = True | |
| for _, row in group.iterrows(): | |
| if first_row: | |
| if current_service is not None: | |
| summary_html += """ | |
| <tr style='background:#37474f;height:3px;'> | |
| <td colspan='7' style='padding:0;border:none;'></td> | |
| </tr>""" | |
| current_service = service_name | |
| service_cell = f""" | |
| <td rowspan='{row_count}' style='padding:10px 15px;border:2px solid #1565c0; | |
| text-align:right;font-weight:bold;color:#fff;background:#1565c0; | |
| vertical-align:middle;'>{service_name}</td>""" | |
| first_row = False | |
| else: | |
| service_cell = "" | |
| summary_html += f""" | |
| <tr style='background:#e3f2fd;'> | |
| {service_cell} | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{row['زیرسرویس']}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{int(row['تعداد_اخبار_ارسالی']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#c8e6c9;color:#000;'>{int(row['اخبار_بالای_هزار']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#c8e6c9;color:#000;'>{int(row['سهم_پربازدید'])}%</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#ffcdd2;color:#000;'>{int(row['اخبار_زیر_200']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;background:#ffcdd2;color:#000;'>{int(row['سهم_کم_بازدید'])}%</td> | |
| </tr>""" | |
| summary_html += f""" | |
| <tr style='background:#1976d2;'> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>جمع کل</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>—</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_ws_news):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_ws_high):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_ws_hp)}%</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_ws_low):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_ws_lp)}%</td> | |
| </tr> | |
| </tbody></table></div>""" | |
| # ── 100 خبر پربازدید ────────────────────────────────────────── | |
| summary_html += """ | |
| <h3 style='color:#ff6f00;margin-top:30px;'>🏆 100 خبر پربازدید ایسنا</h3> | |
| <div style='overflow-x:auto;margin:20px 0;'> | |
| <table style='width:100%;border-collapse:collapse;box-shadow:0 2px 4px rgba(0,0,0,.1);font-size:14px;background:#fff;'> | |
| <thead> | |
| <tr style='background:#1976d2;'> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>تیتر خبر</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>زیرسرویس</th> | |
| """ | |
| if publish_date_col: | |
| summary_html += "<th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>تاریخ انتشار</th>" | |
| summary_html += "<th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>بازدید</th>" | |
| if reporter_col: | |
| summary_html += "<th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>نام خبرنگار</th>" | |
| if publisher_col: | |
| summary_html += "<th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>ناشر</th>" | |
| summary_html += "</tr></thead><tbody>" | |
| for _, row in top_100_news.iterrows(): | |
| summary_html += f""" | |
| <tr style='background:#e3f2fd;'> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{row['تیتر']}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{row['زیرسرویس']}</td>""" | |
| if 'تاریخ_انتشار' in row.index: | |
| summary_html += f"<td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{row['تاریخ_انتشار']}</td>" | |
| summary_html += f"<td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;font-weight:bold;color:#d32f2f;'>{int(row['بازدید']):,}</td>" | |
| if reporter_col: | |
| val = row.get('نام خبرنگار', '-') | |
| summary_html += f"<td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{val if pd.notna(val) else '-'}</td>" | |
| if publisher_col: | |
| val = row.get('ناشر', '-') | |
| summary_html += f"<td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{val if pd.notna(val) else '-'}</td>" | |
| summary_html += "</tr>" | |
| summary_html += "</tbody></table></div>" | |
| # ── پربازدیدترین خبر هر اداره ──────────────────────────────── | |
| summary_html += """ | |
| <h3 style='color:#6a1b9a;margin-top:30px;'>🌟 پربازدیدترین خبر هر اداره</h3> | |
| <div style='overflow-x:auto;margin:20px 0;'> | |
| <table style='width:100%;border-collapse:collapse;box-shadow:0 2px 4px rgba(0,0,0,.1);font-size:14px;background:#fff;'> | |
| <thead> | |
| <tr style='background:#1976d2;'> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>نام اداره</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>تیتر خبر</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>زیرسرویس</th> | |
| """ | |
| if 'تاریخ_انتشار' in top_news_df.columns: | |
| summary_html += "<th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>تاریخ انتشار</th>" | |
| if 'نام_خبرنگار' in top_news_df.columns: | |
| summary_html += "<th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>نام خبرنگار</th>" | |
| summary_html += "<th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>بازدید</th>" | |
| summary_html += "</tr></thead><tbody>" | |
| for _, row in top_news_df.iterrows(): | |
| summary_html += f""" | |
| <tr style='background:#f3e5f5;'> | |
| <td style='padding:10px 15px;border:1px solid #ce93d8;text-align:right;font-weight:bold;color:#4a148c;'>{row['نام_اداره']}</td> | |
| <td style='padding:10px 15px;border:1px solid #ce93d8;text-align:right;color:#000;'>{row['تیتر_خبر']}</td> | |
| <td style='padding:10px 15px;border:1px solid #ce93d8;text-align:right;color:#000;'>{row['زیرسرویس']}</td>""" | |
| if 'تاریخ_انتشار' in row.index: | |
| summary_html += f"<td style='padding:10px 15px;border:1px solid #ce93d8;text-align:right;color:#000;'>{row.get('تاریخ_انتشار', '-')}</td>" | |
| if 'نام_خبرنگار' in row.index: | |
| summary_html += f"<td style='padding:10px 15px;border:1px solid #ce93d8;text-align:right;color:#000;'>{row.get('نام_خبرنگار', '-')}</td>" | |
| summary_html += f"<td style='padding:10px 15px;border:1px solid #ce93d8;text-align:right;font-weight:bold;color:#d32f2f;'>{int(row['بازدید']):,}</td>" | |
| summary_html += "</tr>" | |
| summary_html += "</tbody></table></div>" | |
| # ── میانگین بازدید ──────────────────────────────────────────── | |
| tot_avg_news = avg_stats['تعداد_خبر'].sum() | |
| tot_avg_vis = avg_stats['مجموع_بازدید'].sum() | |
| tot_avg_avg = custom_round(tot_avg_vis / tot_avg_news) if tot_avg_news > 0 else 0 | |
| summary_html += """ | |
| <h3 style='color:#00695c;margin-top:30px;'>📊 میانگین بازدید</h3> | |
| <div style='overflow-x:auto;margin:20px 0;'> | |
| <table style='width:100%;border-collapse:collapse;box-shadow:0 2px 4px rgba(0,0,0,.1);font-size:14px;background:#fff;'> | |
| <thead> | |
| <tr style='background:#1976d2;'> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>عنوان اداره</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>تعداد خبر</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>مجموع بازدید</th> | |
| <th style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;'>میانگین بازدید</th> | |
| </tr> | |
| </thead><tbody> | |
| """ | |
| for _, row in avg_stats.iterrows(): | |
| summary_html += f""" | |
| <tr style='background:#e3f2fd;'> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;font-weight:bold;color:#000;'>{row['عنوان_اداره']}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{int(row['تعداد_خبر']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;color:#000;'>{int(row['مجموع_بازدید']):,}</td> | |
| <td style='padding:10px 15px;border:1px solid #90caf9;text-align:right;font-weight:bold;color:#1976d2;'>{int(row['میانگین_بازدید']):,}</td> | |
| </tr>""" | |
| summary_html += f""" | |
| <tr style='background:#1976d2;'> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>جمع کل</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_avg_news):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_avg_vis):,}</td> | |
| <td style='padding:12px 15px;border:2px solid #1565c0;text-align:right;color:#fff;font-weight:bold;'>{int(tot_avg_avg):,}</td> | |
| </tr> | |
| </tbody></table></div>""" | |
| # آمار کامنت - کاملاً غیرفعال شده طبق درخواست | |
| # ───────────────────────────────────────── | |
| # comment_col_names = { ... } | |
| # comment_stats_list = [] | |
| # for service in df_clean['سرویس_نهایی'].unique(): | |
| # ... (کد کامنت اینجا بود) | |
| # if comment_stats is not None and len(comment_stats) > 0: | |
| # summary_html += "..." # جدول کامنتها | |
| summary_html += """ | |
| <div style='text-align:center;margin-top:40px;padding:20px;background:#e8f5e9;border-radius:8px;'> | |
| <h3 style='color:#2e7d32;'>✅ فایل اکسل با جزئیات کامل آماده دانلود است</h3> | |
| <p style='color:#555;'>شامل: جدول کل ایسنا | آمار تفصیلی سرویسها | 100 خبر پربازدید | | |
| میانگین بازدید | جدول ورد زیرسرویسها | پربازدیدترین خبر هر اداره</p> | |
| </div> | |
| </div>""" | |
| pdf_filename = 'گزارش_ماهانه_ایسنا.pdf' | |
| try: | |
| html_to_pdf(summary_html, pdf_filename) | |
| except Exception as e: | |
| print(f"خطا در تولید PDF: {str(e)}") | |
| pdf_filename = None | |
| return output_filename, summary_html, chart, pdf_filename | |
| except Exception as e: | |
| import traceback | |
| error_html = f""" | |
| <div style='direction:rtl;text-align:right;font-family:Tahoma;padding:20px;'> | |
| <h3 style='color:#d32f2f;'>❌ خطا در پردازش فایل</h3> | |
| <p style='background:#ffebee;padding:15px;border-right:4px solid #d32f2f;'>{str(e)}</p> | |
| <pre style='font-size:11px;color:#666;'>{traceback.format_exc()}</pre> | |
| </div>""" | |
| return None, error_html, None, None | |
| # ───────────────────────────────────────────── | |
| # رابط کاربری Gradio | |
| # ───────────────────────────────────────────── | |
| custom_css = """ | |
| .gradio-container { | |
| direction: rtl; | |
| background-image: url('https://img.freepik.com/free-vector/gradient-brain-background_23-2150516335.jpg'); | |
| background-size: cover; | |
| background-position: center; | |
| background-repeat: no-repeat; | |
| background-attachment: fixed; | |
| } | |
| .contain { | |
| background-color: rgba(255,255,255,0.95); | |
| border-radius: 15px; | |
| padding: 30px; | |
| box-shadow: 0 4px 15px rgba(0,0,0,0.2); | |
| } | |
| #header-box { | |
| background-color: rgba(255,255,255,0.98); | |
| border-radius: 10px; | |
| padding: 25px; | |
| margin-bottom: 20px; | |
| box-shadow: 0 2px 10px rgba(0,0,0,0.1); | |
| } | |
| """ | |
| with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo: | |
| gr.HTML(""" | |
| <div id="header-box" style='text-align:center;direction:rtl;font-family:Tahoma;'> | |
| <h1 style='color:#1976d2;margin-bottom:15px;font-size:28px;'>دستیار هوشمند اتاق خبر - گزارشگیری ماهانه</h1> | |
| <p style='font-size:16px;color:#555;line-height:1.8;'>برای شروع گزارشگیری روی باکس زیر کلیک کرده و فایل لیست تولید و آمار بازدید را وارد نمایید</p> | |
| <hr style='border:1px solid #1976d2;width:50%;margin:20px auto;'> | |
| </div> | |
| """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_file = gr.File( | |
| label="📁 آپلود فایل اکسل اخبار", | |
| file_types=[".xlsx", ".xls"], | |
| type="binary" | |
| ) | |
| submit_btn = gr.Button("🚀 شروع تحلیل آماری", variant="primary", size="lg") | |
| with gr.Row(): | |
| with gr.Column(): | |
| output_html = gr.HTML(label="📊 نتایج تحلیل") | |
| output_chart = gr.Plot(label="📊 نمودار توزیع درصد بازدید اخبار به تفکیک سرویسها") | |
| output_file = gr.File(label="💾 دانلود فایل اکسل نتایج کامل") | |
| output_pdf = gr.File(label="📄 دانلود گزارش PDF") | |
| submit_btn.click( | |
| fn=process_news_data, | |
| inputs=input_file, | |
| outputs=[output_file, output_html, output_chart, output_pdf] | |
| ) | |
| gr.Markdown(""" | |
| <div style='text-align:center;direction:rtl;margin-top:40px;padding:20px;color:#777; | |
| border-top:2px solid #e0e0e0;background:rgba(255,255,255,0.95);border-radius:10px;'> | |
| <p style='font-size:14px;'>💡 <strong>راهنما:</strong> فایل باید شامل ستونهای «تیتر»، «بازدید» و «سرویس» باشد</p> | |
| <p style='font-size:12px;margin-top:10px;'>سامانه هوشمند ایسنا - نسخه ماهانه 2.0 | طراحی شده با ❤️</p> | |
| </div> | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch() |