Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,50 +3,14 @@ import gradio as gr
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
from rich import print
|
5 |
from urllib.parse import urlparse
|
|
|
|
|
6 |
from urllib.parse import parse_qs
|
7 |
|
8 |
def run_lora(prompt,site,start,end):
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
# to search
|
14 |
-
query = "Python programming"
|
15 |
-
url = f"https://www.google.com/search?q=inurl:{site}+{prompt}&tbs=cdr%3A1%2Ccd_min%3A{start}%2Ccd_max%3A {end}"
|
16 |
-
response = requests.get(url)
|
17 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
18 |
-
links = soup.findAll("a")
|
19 |
-
|
20 |
-
j = extract_results(soup)
|
21 |
print(j)
|
22 |
-
|
23 |
-
def extract_results(soup):
|
24 |
-
main = soup.select_one("#main")
|
25 |
-
|
26 |
-
res = []
|
27 |
-
for gdiv in main.select('.g, .fP1Qef'):
|
28 |
-
res.append(extract_section(gdiv))
|
29 |
-
return res
|
30 |
-
|
31 |
-
def extract_section(gdiv):
|
32 |
-
# Getting our elements
|
33 |
-
title = gdiv.select_one('h3')
|
34 |
-
link = gdiv.select_one('a')
|
35 |
-
description = gdiv.find('.BNeawe')
|
36 |
-
return {
|
37 |
-
# Extract title's text only if text is found
|
38 |
-
'title': title.text if title else None,
|
39 |
-
|
40 |
-
'link': extract_href(link['href']) if link else None,
|
41 |
-
'description': description.text if description else None
|
42 |
-
}
|
43 |
-
def extract_href(href):
|
44 |
-
url = urlparse(href)
|
45 |
-
query = parse_qs(url.query)
|
46 |
-
if not ('q' in query and query['q'] and len(query['q']) > 0):
|
47 |
-
return None
|
48 |
-
return query['q'][0]
|
49 |
-
|
50 |
|
51 |
with gr.Blocks() as app:
|
52 |
gr.HTML("""<html>
|
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
from rich import print
|
5 |
from urllib.parse import urlparse
|
6 |
+
|
7 |
+
from googlesearch import search
|
8 |
from urllib.parse import parse_qs
|
9 |
|
10 |
def run_lora(prompt,site,start,end):
|
11 |
|
12 |
+
j = search("inurl:"+site +"+"+ prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
print(j)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
with gr.Blocks() as app:
|
16 |
gr.HTML("""<html>
|