Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,59 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import random
|
3 |
-
from scraperr import scrape_google
|
4 |
-
from pdf_converter import DocumentHandler
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
async def scrape_websites(topic, num_links, num_results_per_link=10):
|
9 |
-
output_text = await scrape_google(topic, num_results_per_link)
|
10 |
-
# Ensure output_text is a list
|
11 |
-
if not isinstance(output_text, list):
|
12 |
-
output_text = [output_text]
|
13 |
-
# Select random links based on the user's input
|
14 |
-
selected_links = random.sample(output_text, min(num_links, len(output_text)))
|
15 |
-
# Convert the list of strings to a single string
|
16 |
-
output_string = "\n".join(selected_links)
|
17 |
-
return output_string
|
18 |
-
|
19 |
-
def convert_to_pdf(url):
|
20 |
-
document_handler = DocumentHandler(url)
|
21 |
-
pdf_path = document_handler.create_pdf()
|
22 |
-
return pdf_path
|
23 |
-
|
24 |
-
html = """
|
25 |
-
<div style="text-align:center; max-width: 900px; margin: 0 auto; margin-top:5px">
|
26 |
-
<h1>Research Assistant</h1>
|
27 |
-
<p> Welcome to the Research Assistant app! This tool helps you find relevant information on your topic of interest.</p>
|
28 |
-
</div>"""
|
29 |
-
css = """container{max-width:900px; margin-left:auto; margin-right:auto;padding:20px}"""
|
30 |
-
|
31 |
-
with gr.Blocks(css=css,theme=gr.themes.Monochrome( primary_hue= gr.themes.colors.orange , secondary_hue=gr.themes.colors.blue,neutral_hue=gr.themes.colors.gray,radius_size=gr.themes.sizes.radius_md)) as demo:
|
32 |
-
gr.HTML(html)
|
33 |
-
with gr.Tab("Scrape Google"):
|
34 |
-
with gr.Row():
|
35 |
-
with gr.Column(variant="panel"):
|
36 |
-
|
37 |
-
topic = gr.Textbox(label="What is your Research Topic?", container= True)
|
38 |
-
num_links = gr.Slider(label="Specify the Number of Links to Scrape!",minimum= 0, container= True)
|
39 |
-
text_button = gr.Button("Scrape")
|
40 |
-
|
41 |
-
with gr.Column(min_width=600):
|
42 |
-
text_output = gr.Textbox(label="Result", lines= 10, container=True, autoscroll=False)
|
43 |
-
|
44 |
-
text_button.click(scrape_websites, inputs=[topic, num_links], outputs=text_output, scroll_to_output=False)
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
with gr.Tab("Convert To PDF"):
|
49 |
-
url_input = gr.Textbox(label="URL")
|
50 |
-
pdf_button = gr.Button("Convert")
|
51 |
-
pdf_output = gr.File(label="PDF")
|
52 |
-
pdf_button.click(convert_to_pdf, inputs=url_input, outputs=pdf_output)
|
53 |
-
chat_bot_button = gr.Button("Proceed to ChatBot", link="https://huggingface.co/spaces/lara1510/chatbot")
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
if __name__ == "__main__":
|
59 |
-
demo.launch(share = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|