querysurvey / app.py
adpro's picture
Update app.py
54811ce verified
raw
history blame
2.12 kB
import requests
import gradio as gr
from bs4 import BeautifulSoup
from rich import print
from urllib.parse import urlparse
from googlesearch import search
from urllib.parse import parse_qs
def run_lora(prompt,site,start,end):
j = "https://www.google.com/search?q=inurl:"+site +"+"+ prompt + "&tbs=cdr%3A1%2Ccd_min%3A"+start+"%2Ccd_max%3A" + end
links=""
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5)\
AppleWebKit/537.36 (KHTML, like Gecko) Cafari/537.36'}
page = requests.get(j, headers = headers)
soup = BeautifulSoup(page.content, "html.parser")
import re
links = soup.findAll("a")
mLink=""
#for link in soup.find_all("a", "html.parser", parse_only=SoupStrainer('a')):
for link in soup.find_all("a",href=re.compile("(?<=/url\?q=)(htt.*://.*)")):
jjj =re.split(":(?=http)",link["href"].replace("/url?q=",""))
jj = extract_href(link["href"])
print(jjj)
mLink+=str(jjj)
return mLink
def extract_href(href):
url = urlparse(href)
query = parse_qs(url.query)
if not ('q' in query and query['q'] and len(query['q']) > 0):
return None
return query['q'][0]
with gr.Blocks() as app:
gr.HTML("""<html>
<head>
<style>
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1>Get survey</h1>
</body>
</html>""")
with gr.Row():
with gr.Column():
input_textbox = gr.Textbox(lines=5, placeholder="Enter key", label="Input Text")
input_sitebox = gr.Textbox(lines=5, placeholder="Enter site", label="Site Text")
start = gr.Textbox(lines=5, placeholder="Enter start", label="Enter start")
end = gr.Textbox(lines=5, placeholder="Enter End", label="Enter End")
with gr.Column():
translated_textbox = gr.Textbox(lines=5, placeholder="", label="Result Text")
info_label = gr.HTML("")
btn = gr.Button("GetNow")
btn.click(run_lora, inputs=[input_textbox,input_sitebox,start,end],outputs=[translated_textbox])
app.queue()
app.launch()