alibidaran commited on
Commit
a897c22
·
verified ·
1 Parent(s): b9ff25b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from hazm import *
2
+ import gradio as gr
3
+ from sklearn.decomposition import LatentDirichletAllocation
4
+ from sklearn.feature_extraction.text import CountVectorizer
5
+ lda = LatentDirichletAllocation(n_components=4,random_state=101)
6
+ normalizer=Normalizer()
7
+ lemmatizer=Lemmatizer()
8
+ stemmer=Stemmer()
9
+ vectorzer=CountVectorizer(analyzer='word', ngram_range=(1,1))
10
+ def compute_seo_score(normalized_text,keywords):
11
+ tokens=sent_tokenize(normalized_text)
12
+ x=vectorzer.fit_transform([normalized_text])
13
+ features=lda.fit(x)
14
+ key_words=[vectorzer.get_feature_names_out()[index] for index in features.components_.argsort()[-10:]]
15
+ query_terms=keywords.split('-')
16
+ score=0
17
+ for i in range(len(key_words)):
18
+ for query in query_terms:
19
+ keyterms=key_words[i]
20
+ if query in [lemmatizer.lemmatize(word) for word in key_words[i]]:
21
+ score+=1
22
+ final_score=score/4
23
+ return {'Estimated_number':score/100,
24
+ 'score':final_score/100}
25
+ def Normalize_text(text,keywords):
26
+ normalized_text=normalizer.normalize(text)
27
+ label=compute_seo_score(normalized_text,keywords)
28
+ return normalized_text,label
29
+ demo = gr.Interface(
30
+ fn=Normalize_text,
31
+ inputs=["text","text"],
32
+ outputs=["text","label"],
33
+ )
34
+ demo.launch()