jaimin commited on
Commit
2152aac
·
1 Parent(s): 8cf15dc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gensim.parsing.preprocessing import STOPWORDS
2
+ import wikipedia
3
+ import gradio as gr
4
+ from gradio.mix import Parallel
5
+ import requests
6
+ import nltk
7
+ from nltk.tokenize import word_tokenize
8
+ from nltk.tokenize import sent_tokenize
9
+ import re
10
+ nltk.download('punkt')
11
+
12
+
13
+ def opendomain(text):
14
+ question_words = STOPWORDS.union(set(['likes','play','.',',','like',"don't",'?','use','choose','important','better','?']))
15
+ lower_text = text.lower()
16
+ lower_text = word_tokenize(lower_text)
17
+ new_text = [i for i in lower_text if i not in question_words]
18
+ new_txt = "".join(new_text)
19
+
20
+ r = requests.post(
21
+ url="https://jaimin-new-content.hf.space/run/predict",
22
+ json={"data": [new_txt, "en"]},
23
+ )
24
+ response = r.json()
25
+ text1 = response["data"]
26
+ final_out = text1[0]
27
+ final_out=re.sub(r'\=.+\=', '', final_out)
28
+
29
+ result = list(filter(lambda x: x != '', final_out.split('\n\n')))
30
+
31
+ answer = []
32
+ for i in range(6):
33
+ if len(result[i]) > 500:
34
+ summary_point=result[i].split(".")[0]
35
+ answer.append(summary_point)
36
+ l = []
37
+ for i in range(len(answer)):
38
+ l.append("".join(answer[i]))
39
+ gen_output = []
40
+ for i in range(len(l)):
41
+ gen_output.append(l[i] + ".")
42
+
43
+ listToStr = ' '.join([str(elem) for elem in gen_output])
44
+ listToStr = listToStr.replace("\n", "")
45
+ return listToStr
46
+ #return final_answer
47
+
48
+
49
+ iface = gr.Interface(fn=opendomain, inputs=[gr.inputs.Textbox(lines=5)], outputs="text")
50
+ iface.launch()