Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from collections import Counter
|
3 |
from bs4 import BeautifulSoup
|
4 |
-
import pandas as pd
|
5 |
|
6 |
|
7 |
# دالة استخراج العناوين والهاشتاغات
|
@@ -10,7 +9,7 @@ def extract_titles_and_hashtags(file):
|
|
10 |
# قراءة محتوى الملف
|
11 |
content = file.read() if hasattr(file, 'read') else open(file.name, 'r', encoding='utf-8').read()
|
12 |
except Exception as e:
|
13 |
-
return f"خطأ أثناء قراءة الملف: {str(e)}", ""
|
14 |
|
15 |
# تحليل HTML باستخدام BeautifulSoup
|
16 |
soup = BeautifulSoup(content, 'html.parser')
|
@@ -21,7 +20,7 @@ def extract_titles_and_hashtags(file):
|
|
21 |
|
22 |
desc_containers = soup.find_all('div', class_="css-vi46v1-DivDesContainer")
|
23 |
if not desc_containers:
|
24 |
-
return "لم يتم العثور على أي بيانات مطابقة.", ""
|
25 |
|
26 |
for container in desc_containers:
|
27 |
title = container.get('aria-label', 'بدون عنوان')
|
@@ -36,8 +35,9 @@ def extract_titles_and_hashtags(file):
|
|
36 |
# تحويل النتائج إلى نصوص
|
37 |
titles_text = "\n".join([f"{i+1}. {row['Title']}" for i, row in enumerate(data)])
|
38 |
hashtags_text = "\n".join([f"{hashtag}: {count}" for hashtag, count in hashtags_counter.items()])
|
|
|
39 |
|
40 |
-
return titles_text or "لا توجد عناوين مستخرجة.", hashtags_text or "لا توجد هاشتاغات مستخرجة."
|
41 |
|
42 |
|
43 |
# إنشاء واجهة Gradio
|
@@ -59,16 +59,22 @@ def gradio_interface():
|
|
59 |
placeholder="ستظهر العناوين هنا"
|
60 |
)
|
61 |
hashtags_output = gr.Textbox(
|
62 |
-
label="🏷️ الهاشتاغات المستخرجة",
|
63 |
lines=10,
|
64 |
interactive=False,
|
65 |
placeholder="ستظهر الهاشتاغات هنا"
|
66 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
analyze_btn.click(
|
69 |
fn=extract_titles_and_hashtags,
|
70 |
inputs=[file_input],
|
71 |
-
outputs=[titles_output, hashtags_output],
|
72 |
)
|
73 |
|
74 |
return demo
|
|
|
1 |
import gradio as gr
|
2 |
from collections import Counter
|
3 |
from bs4 import BeautifulSoup
|
|
|
4 |
|
5 |
|
6 |
# دالة استخراج العناوين والهاشتاغات
|
|
|
9 |
# قراءة محتوى الملف
|
10 |
content = file.read() if hasattr(file, 'read') else open(file.name, 'r', encoding='utf-8').read()
|
11 |
except Exception as e:
|
12 |
+
return f"خطأ أثناء قراءة الملف: {str(e)}", "", ""
|
13 |
|
14 |
# تحليل HTML باستخدام BeautifulSoup
|
15 |
soup = BeautifulSoup(content, 'html.parser')
|
|
|
20 |
|
21 |
desc_containers = soup.find_all('div', class_="css-vi46v1-DivDesContainer")
|
22 |
if not desc_containers:
|
23 |
+
return "لم يتم العثور على أي بيانات مطابقة.", "", ""
|
24 |
|
25 |
for container in desc_containers:
|
26 |
title = container.get('aria-label', 'بدون عنوان')
|
|
|
35 |
# تحويل النتائج إلى نصوص
|
36 |
titles_text = "\n".join([f"{i+1}. {row['Title']}" for i, row in enumerate(data)])
|
37 |
hashtags_text = "\n".join([f"{hashtag}: {count}" for hashtag, count in hashtags_counter.items()])
|
38 |
+
unique_hashtags_text = "\n".join(hashtags_counter.keys()) # هاشتاغات غير مكررة
|
39 |
|
40 |
+
return titles_text or "لا توجد عناوين مستخرجة.", hashtags_text or "لا توجد هاشتاغات مستخرجة.", unique_hashtags_text or "لا توجد هاشتاغات فريدة."
|
41 |
|
42 |
|
43 |
# إنشاء واجهة Gradio
|
|
|
59 |
placeholder="ستظهر العناوين هنا"
|
60 |
)
|
61 |
hashtags_output = gr.Textbox(
|
62 |
+
label="🏷️ الهاشتاغات المستخرجة (مع التكرار)",
|
63 |
lines=10,
|
64 |
interactive=False,
|
65 |
placeholder="ستظهر الهاشتاغات هنا"
|
66 |
)
|
67 |
+
unique_hashtags_output = gr.Textbox(
|
68 |
+
label="🏷️ الهاشتاغات الفريدة (غير المكررة)",
|
69 |
+
lines=10,
|
70 |
+
interactive=False,
|
71 |
+
placeholder="ستظهر الهاشتاغات الفريدة هنا"
|
72 |
+
)
|
73 |
|
74 |
analyze_btn.click(
|
75 |
fn=extract_titles_and_hashtags,
|
76 |
inputs=[file_input],
|
77 |
+
outputs=[titles_output, hashtags_output, unique_hashtags_output],
|
78 |
)
|
79 |
|
80 |
return demo
|