Update app.py
Browse files
app.py
CHANGED
@@ -76,7 +76,34 @@ def aitext(word):
|
|
76 |
|
77 |
return response.choices[0].text
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
def google(name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
result = {"",""}
|
81 |
text =""
|
82 |
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:
|
@@ -91,13 +118,13 @@ def google(name):
|
|
91 |
soup = BeautifulSoup(r.text,"html.parser")
|
92 |
|
93 |
heading_object=soup.find_all('div')
|
94 |
-
|
95 |
for info in heading_object:
|
96 |
-
|
97 |
|
98 |
if '<div class="BNeawe s3v9rd AP7Wnd"><div><div><div class="BNeawe s3v9rd AP7Wnd">' in str(info):
|
99 |
if '›' not in str(info.text) :
|
100 |
result.add(info.text)
|
|
|
101 |
n=0
|
102 |
for i in result:
|
103 |
if n!=0:
|
@@ -111,7 +138,27 @@ def google(name):
|
|
111 |
i = i[0]
|
112 |
text = text +str(n)+"\t"+i+"\n\n"
|
113 |
n=n+1
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
def greet(name1):
|
117 |
name = name1.lower()
|
|
|
76 |
|
77 |
return response.choices[0].text
|
78 |
|
79 |
+
import json
|
80 |
+
headers = {"Authorization": f"Bearer {'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'}"}
|
81 |
+
def sumy(payload):
|
82 |
+
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
|
83 |
+
data = json.dumps(payload)
|
84 |
+
response = requests.request("POST", API_URL, headers=headers, data=data)
|
85 |
+
return json.loads(response.content.decode("utf-8"))
|
86 |
+
|
87 |
+
|
88 |
+
def query(payload):
|
89 |
+
API_URL = "https://api-inference.huggingface.co/models/gpt2"
|
90 |
+
data = json.dumps(payload)
|
91 |
+
response = requests.request("POST", API_URL, headers=headers, data=data)
|
92 |
+
return json.loads(response.content.decode("utf-8"))
|
93 |
+
|
94 |
def google(name):
|
95 |
+
if "give" in name:
|
96 |
+
r_c = name.split("give")[1]
|
97 |
+
|
98 |
+
result_count = int(r_c.split()[0])
|
99 |
+
#print(result_count)
|
100 |
+
name = name.split("give")[0]
|
101 |
+
print(name)
|
102 |
+
|
103 |
+
else:
|
104 |
+
result_count = 1
|
105 |
+
|
106 |
+
f_result = ""
|
107 |
result = {"",""}
|
108 |
text =""
|
109 |
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:
|
|
|
118 |
soup = BeautifulSoup(r.text,"html.parser")
|
119 |
|
120 |
heading_object=soup.find_all('div')
|
121 |
+
|
122 |
for info in heading_object:
|
|
|
123 |
|
124 |
if '<div class="BNeawe s3v9rd AP7Wnd"><div><div><div class="BNeawe s3v9rd AP7Wnd">' in str(info):
|
125 |
if '›' not in str(info.text) :
|
126 |
result.add(info.text)
|
127 |
+
|
128 |
n=0
|
129 |
for i in result:
|
130 |
if n!=0:
|
|
|
138 |
i = i[0]
|
139 |
text = text +str(n)+"\t"+i+"\n\n"
|
140 |
n=n+1
|
141 |
+
|
142 |
+
if result_count == 1:
|
143 |
+
temp = ""
|
144 |
+
for r in text.split("\n\n"):
|
145 |
+
temp = temp+r.split("...")[0]
|
146 |
+
f_result = sumy({"inputs":temp,"parameters": {"do_sample": False,"max_length":300}})
|
147 |
+
return f_result[0]['summary_text']
|
148 |
+
else:
|
149 |
+
for r in text.split("\n\n"):
|
150 |
+
if "..." in r:
|
151 |
+
r = r.split("...")
|
152 |
+
print(r[0].strip(),1)
|
153 |
+
w = query(r[0].strip())[0]['generated_text'].strip()
|
154 |
+
if "\n\n" in w:
|
155 |
+
print("=")
|
156 |
+
f_result = f_result +w+"\n\n"
|
157 |
+
else:
|
158 |
+
print("=")
|
159 |
+
f_result = f_result + r.strip()+"\n\n"
|
160 |
+
|
161 |
+
return f_result
|
162 |
|
163 |
def greet(name1):
|
164 |
name = name1.lower()
|