Update app.py
Browse files
app.py
CHANGED
|
@@ -7,25 +7,7 @@ from bs4 import BeautifulSoup
|
|
| 7 |
from datetime import datetime
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
from wordcloud import WordCloud
|
| 10 |
-
|
| 11 |
-
from textblob import TextBlob
|
| 12 |
-
import nltk
|
| 13 |
-
|
| 14 |
-
# تنزيل البيانات المطلوبة لـ NLTK و TextBlob إذا لم تكن موجودة
|
| 15 |
-
def download_nltk_data():
|
| 16 |
-
import os
|
| 17 |
-
nltk_data_path = os.path.join(os.getcwd(), 'nltk_data')
|
| 18 |
-
if not os.path.exists(nltk_data_path):
|
| 19 |
-
os.makedirs(nltk_data_path)
|
| 20 |
-
nltk.data.path.append(nltk_data_path)
|
| 21 |
-
required_packages = ['wordnet', 'punkt', 'averaged_perceptron_tagger', 'brown']
|
| 22 |
-
for package in required_packages:
|
| 23 |
-
try:
|
| 24 |
-
nltk.data.find(f'corpora/{package}')
|
| 25 |
-
except LookupError:
|
| 26 |
-
nltk.download(package, download_dir=nltk_data_path)
|
| 27 |
-
|
| 28 |
-
download_nltk_data()
|
| 29 |
|
| 30 |
# إعداد العربية في Streamlit
|
| 31 |
st.set_page_config(page_title="أداة تحليل المواقع", layout="wide")
|
|
@@ -65,14 +47,19 @@ def main():
|
|
| 65 |
meta_desc = soup.find('meta', attrs={'name': 'description'})
|
| 66 |
meta_desc_content = meta_desc['content'].strip() if meta_desc else "لم يتم العثور على ميتا الوصف"
|
| 67 |
|
| 68 |
-
# تحليل الكلمات المفتاحية
|
| 69 |
texts = soup.get_text()
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# رسم سحابة الكلمات
|
| 75 |
-
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(
|
| 76 |
fig_wc, ax_wc = plt.subplots(figsize=(12, 6))
|
| 77 |
ax_wc.imshow(wordcloud, interpolation='bilinear')
|
| 78 |
ax_wc.axis('off')
|
|
|
|
| 7 |
from datetime import datetime
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
from wordcloud import WordCloud
|
| 10 |
+
# تم إزالة TextBlob و NLTK
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# إعداد العربية في Streamlit
|
| 13 |
st.set_page_config(page_title="أداة تحليل المواقع", layout="wide")
|
|
|
|
| 47 |
meta_desc = soup.find('meta', attrs={'name': 'description'})
|
| 48 |
meta_desc_content = meta_desc['content'].strip() if meta_desc else "لم يتم العثور على ميتا الوصف"
|
| 49 |
|
| 50 |
+
# تحليل الكلمات المفتاحية (بدون TextBlob و NLTK)
|
| 51 |
texts = soup.get_text()
|
| 52 |
+
# تقسيم النص إلى كلمات واستبعاد الكلمات الشائعة
|
| 53 |
+
words = texts.lower().split()
|
| 54 |
+
common_words = set(['و', 'في', 'من', 'على', 'أن', 'إلى', 'عن', 'هو', 'مع', 'هذا', 'ما', 'لم', 'كما', 'كل'])
|
| 55 |
+
filtered_words = [word for word in words if word.isalpha() and word not in common_words]
|
| 56 |
+
word_counts = {}
|
| 57 |
+
for word in filtered_words:
|
| 58 |
+
word_counts[word] = word_counts.get(word, 0) + 1
|
| 59 |
+
sorted_keywords = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)[:10]
|
| 60 |
|
| 61 |
# رسم سحابة الكلمات
|
| 62 |
+
wordcloud = WordCloud(width=800, height=400, background_color='white', font_path='arial').generate(' '.join(filtered_words))
|
| 63 |
fig_wc, ax_wc = plt.subplots(figsize=(12, 6))
|
| 64 |
ax_wc.imshow(wordcloud, interpolation='bilinear')
|
| 65 |
ax_wc.axis('off')
|