Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,65 @@ from bs4 import BeautifulSoup
|
|
5 |
import pyjokes
|
6 |
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def code(name):
|
9 |
name = name.split('learn')[-1]
|
10 |
name = name.split('start')[-1]
|
@@ -174,6 +233,9 @@ def greet(name1):
|
|
174 |
return "Im not a human so i don't have age"
|
175 |
if "thank u" in name or "thanks" in name or "thank you" in name:
|
176 |
return "ok welcome ....!"
|
|
|
|
|
|
|
177 |
if "how to learn" in name or "steps for learning" in name or "step for learning" in name or "steps for" in name or "step for" in name:
|
178 |
try:
|
179 |
cresult = code(name)
|
|
|
5 |
import pyjokes
|
6 |
|
7 |
|
8 |
+
|
9 |
+
def essay_query(payload):
|
10 |
+
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
|
11 |
+
data = json.dumps(payload)
|
12 |
+
response = requests.request("POST", API_URL, headers=headers, data=data)
|
13 |
+
return json.loads(response.content.decode("utf-8"))
|
14 |
+
|
15 |
+
def essay(name):
|
16 |
+
|
17 |
+
result_count = 2
|
18 |
+
|
19 |
+
f_result = ""
|
20 |
+
result = {"",""}
|
21 |
+
text =""
|
22 |
+
|
23 |
+
url = "https://www.google.com/search?q="+name
|
24 |
+
r = requests.get(url)
|
25 |
+
|
26 |
+
soup = BeautifulSoup(r.text,"html.parser")
|
27 |
+
|
28 |
+
heading_object=soup.find_all('div')
|
29 |
+
|
30 |
+
for info in heading_object:
|
31 |
+
|
32 |
+
if '<div class="BNeawe s3v9rd AP7Wnd"><div><div><div class="BNeawe s3v9rd AP7Wnd">' in str(info):
|
33 |
+
if '›' not in str(info.text) :
|
34 |
+
result.add(info.text)
|
35 |
+
|
36 |
+
n=0
|
37 |
+
for i in result:
|
38 |
+
if n!=0:
|
39 |
+
i = i.split("·",1)
|
40 |
+
try:
|
41 |
+
i = i[1]
|
42 |
+
except:
|
43 |
+
i = i[0]
|
44 |
+
i=i.split("Duration")
|
45 |
+
|
46 |
+
i = i[0]
|
47 |
+
text = text +str(n)+"\t"+i+"\n\n"
|
48 |
+
n=n+1
|
49 |
+
|
50 |
+
if result_count == 1:
|
51 |
+
temp = ""
|
52 |
+
|
53 |
+
else:
|
54 |
+
for r in text.split("\n\n")[0:-1]:
|
55 |
+
if "..." in r:
|
56 |
+
r = r.split("...")
|
57 |
+
w = essay_query(r[0].replace("\xa0",""))
|
58 |
+
f_result = f_result + (w[0]['summary_text'])
|
59 |
+
else:
|
60 |
+
#print(r[:-1])
|
61 |
+
w = essay_query(r[:-1])
|
62 |
+
f_result = f_result +(w[0]['summary_text'])
|
63 |
+
return f_result
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
def code(name):
|
68 |
name = name.split('learn')[-1]
|
69 |
name = name.split('start')[-1]
|
|
|
233 |
return "Im not a human so i don't have age"
|
234 |
if "thank u" in name or "thanks" in name or "thank you" in name:
|
235 |
return "ok welcome ....!"
|
236 |
+
if "write the essay" in name or "write essay" in name:
|
237 |
+
name = name.split("about")[-1]
|
238 |
+
return essay(name)
|
239 |
if "how to learn" in name or "steps for learning" in name or "step for learning" in name or "steps for" in name or "step for" in name:
|
240 |
try:
|
241 |
cresult = code(name)
|