Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import nltk
|
|
4 |
from nltk.tokenize import word_tokenize, sent_tokenize
|
5 |
from nltk.corpus import stopwords
|
6 |
from nltk.stem import WordNetLemmatizer
|
|
|
7 |
from nltk.probability import FreqDist
|
8 |
from cleantext import clean
|
9 |
import textract
|
@@ -31,8 +32,9 @@ import contractions
|
|
31 |
load_dotenv()
|
32 |
|
33 |
# Download NLTK resources
|
34 |
-
nltk.download(['
|
35 |
-
|
|
|
36 |
# Initialize Groq client
|
37 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
38 |
groq_client = groq.Groq(api_key=groq_api_key) if groq_api_key else None
|
@@ -138,10 +140,24 @@ def fDistancePlot(text2Party):
|
|
138 |
return safe_plot(lambda: FreqDist(word_tokenize(text2Party)).plot(15, title='Frequency Distribution'))
|
139 |
|
140 |
def DispersionPlot(textParty):
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
def word_cloud_generator(parsed_text_name, text_Party):
|
147 |
try:
|
|
|
4 |
from nltk.tokenize import word_tokenize, sent_tokenize
|
5 |
from nltk.corpus import stopwords
|
6 |
from nltk.stem import WordNetLemmatizer
|
7 |
+
from nltk.text import Text
|
8 |
from nltk.probability import FreqDist
|
9 |
from cleantext import clean
|
10 |
import textract
|
|
|
32 |
load_dotenv()
|
33 |
|
34 |
# Download NLTK resources
|
35 |
+
nltk.download(['stopwords', 'wordnet', 'words'])
|
36 |
+
nltk.download('punkt')
|
37 |
+
nltk.download('punkt_tab')
|
38 |
# Initialize Groq client
|
39 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
40 |
groq_client = groq.Groq(api_key=groq_api_key) if groq_api_key else None
|
|
|
140 |
return safe_plot(lambda: FreqDist(word_tokenize(text2Party)).plot(15, title='Frequency Distribution'))
|
141 |
|
142 |
def DispersionPlot(textParty):
|
143 |
+
try:
|
144 |
+
word_tokens_party = word_tokenize(textParty)
|
145 |
+
moby = Text(word_tokens_party) # Ensure Text is imported
|
146 |
+
fdistance = FreqDist(word_tokens_party)
|
147 |
+
word_Lst = [fdistance.most_common(6)[x][0] for x in range(5)]
|
148 |
+
plt.figure(figsize=(4, 3))
|
149 |
+
plt.title('Dispersion Plot')
|
150 |
+
moby.dispersion_plot(word_Lst)
|
151 |
+
plt.tight_layout()
|
152 |
+
buf = BytesIO()
|
153 |
+
plt.savefig(buf, format='png')
|
154 |
+
buf.seek(0)
|
155 |
+
img = Image.open(buf)
|
156 |
+
plt.clf()
|
157 |
+
return img
|
158 |
+
except Exception as e:
|
159 |
+
print(f"Dispersion plot error: {e}")
|
160 |
+
return None
|
161 |
|
162 |
def word_cloud_generator(parsed_text_name, text_Party):
|
163 |
try:
|