fdaudens HF staff commited on
Commit
d7c693f
1 Parent(s): b7d27f0

first commit

Browse files
Files changed (4) hide show
  1. README.md +26 -1
  2. app.py +70 -0
  3. packages.txt +8 -0
  4. requirements.txt +5 -0
README.md CHANGED
@@ -8,5 +8,30 @@ sdk_version: 4.31.4
8
  app_file: app.py
9
  pinned: false
10
  ---
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
+ # Scrape and Summarize Web Content with AI
12
 
13
+ ## Overview
14
+
15
+ This project provides an easy way to scrape and summarize web content using advanced AI models hosted on Hugging Face. It leverages the capabilities of ScrapeGraphAI and integrates a user-friendly interface with Gradio. The project allows users to input a prompt and a source URL to obtain summarized web content without writing any code.
16
+
17
+ ## Features
18
+
19
+ - **No-code interface**: Easily scrape and summarize web content.
20
+ - **Advanced AI models**: Utilizes Hugging Face models for language processing and embeddings.
21
+ - **Gradio integration**: User-friendly interface to interact with the models.
22
+ - **Customizable**: Change models and configurations as needed. (coming soon)
23
+
24
+ ## Configuration
25
+
26
+ - **Models**:
27
+ - The project uses `Mistral-7B-Instruct-v0.2` for the language model and `sentence-transformers/all-MiniLM-l6-v2` for embeddings.
28
+
29
+ ## Contributing
30
+
31
+ Contributions are welcome! Please submit pull requests or open issues to suggest improvements.
32
+
33
+ ## Acknowledgements
34
+
35
+ - [ScrapeGraphAI](https://github.com/VinciGit00/Scrapegraph-ai)
36
+ - [Hugging Face](https://huggingface.co/)
37
+ - [Gradio](https://gradio.app/)
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from scrapegraphai.graphs import SmartScraperGraph
4
+ from scrapegraphai.utils import prettify_exec_info
5
+ from langchain_community.llms import HuggingFaceEndpoint
6
+ from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
7
+ import gradio as gr
8
+ import subprocess
9
+
10
+ # Ensure Playwright installs required browsers and dependencies
11
+ subprocess.run(["playwright", "install"])
12
+ #subprocess.run(["playwright", "install-deps"])
13
+
14
+ # Load environment variables
15
+ load_dotenv()
16
+ HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')
17
+
18
+ # Initialize the model instances
19
+ repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
20
+ llm_model_instance = HuggingFaceEndpoint(
21
+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN
22
+ )
23
+
24
+ embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(
25
+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"
26
+ )
27
+
28
+ graph_config = {
29
+ "llm": {"model_instance": llm_model_instance},
30
+ "embeddings": {"model_instance": embedder_model_instance}
31
+ }
32
+
33
+ def scrape_and_summarize(prompt, source):
34
+ smart_scraper_graph = SmartScraperGraph(
35
+ prompt=prompt,
36
+ source=source,
37
+ config=graph_config
38
+ )
39
+ result = smart_scraper_graph.run()
40
+ exec_info = smart_scraper_graph.get_execution_info()
41
+ return result, prettify_exec_info(exec_info)
42
+
43
+ # Gradio interface
44
+ with gr.Blocks() as demo:
45
+ gr.Markdown("# Scrape websites, no-code version")
46
+ gr.Markdown("""Easily scrape and summarize web content using advanced AI models on the Hugging Face Hub without writing any code. Input your desired prompt and source URL to get started.
47
+ This is a no-code version of the excellent lib [ScrapeGraphAI](https://github.com/VinciGit00/Scrapegraph-ai).
48
+ It's a basic demo and a work in progress. Please contribute to it to make it more useful!""")
49
+
50
+ with gr.Row():
51
+ with gr.Column():
52
+
53
+ model_dropdown = gr.Textbox(label="Model", value="Mistral-7B-Instruct-v0.2")
54
+ prompt_input = gr.Textbox(label="Prompt", value="List me all the press releases with their headlines and urls.")
55
+ source_input = gr.Textbox(label="Source URL", value="https://www.whitehouse.gov/")
56
+ scrape_button = gr.Button("Scrape and Summarize")
57
+
58
+ with gr.Column():
59
+ result_output = gr.Textbox(label="Result")
60
+ exec_info_output = gr.Textbox(label="Execution Info")
61
+
62
+ scrape_button.click(
63
+ scrape_and_summarize,
64
+ inputs=[prompt_input, source_input],
65
+ outputs=[result_output, exec_info_output]
66
+ )
67
+
68
+ # Launch the Gradio app
69
+ if __name__ == "__main__":
70
+ demo.launch()
packages.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ libnss3
2
+ libnspr4
3
+ libatk1.0-0
4
+ libatk-bridge2.0-0
5
+ libcups2
6
+ libatspi2.0-0
7
+ libxcomposite1
8
+ libxdamage1
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio==4.31.3
2
+ langchain_community==0.0.38
3
+ python-dotenv==1.0.1
4
+ scrapegraphai==1.2.3
5
+ playwright==1.43.0