sadidul012 commited on
Commit
ade1ed5
1 Parent(s): a857221

Added model

Browse files
Files changed (1) hide show
  1. app.py +67 -4
app.py CHANGED
@@ -1,9 +1,72 @@
 
 
 
 
 
 
1
  import gradio as gr
 
2
 
 
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
 
6
 
 
 
 
 
 
7
 
8
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
34
+ def scrape_and_summarize(prompt, source):
35
+ smart_scraper_graph = SmartScraperGraph(
36
+ prompt=prompt,
37
+ source=source,
38
+ config=graph_config
39
+ )
40
+ result = smart_scraper_graph.run()
41
+ exec_info = smart_scraper_graph.get_execution_info()
42
+ return result, prettify_exec_info(exec_info)
43
+
44
+
45
+ # Gradio interface
46
+ with gr.Blocks() as demo:
47
+ gr.Markdown("# Scrape websites, no-code version")
48
+ 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.
49
+ This is a no-code version of the excellent lib [ScrapeGraphAI](https://github.com/VinciGit00/Scrapegraph-ai).
50
+ It's a basic demo and a work in progress. Please contribute to it to make it more useful!""")
51
+
52
+ with gr.Row():
53
+ with gr.Column():
54
+ model_dropdown = gr.Textbox(label="Model", value="Mistral-7B-Instruct-v0.2")
55
+ prompt_input = gr.Textbox(label="Prompt",
56
+ value="List me all the press releases with their headlines and urls.")
57
+ source_input = gr.Textbox(label="Source URL", value="https://www.whitehouse.gov/")
58
+ scrape_button = gr.Button("Scrape and Summarize")
59
+
60
+ with gr.Column():
61
+ result_output = gr.JSON(label="Result")
62
+ exec_info_output = gr.Textbox(label="Execution Info")
63
+
64
+ scrape_button.click(
65
+ scrape_and_summarize,
66
+ inputs=[prompt_input, source_input],
67
+ outputs=[result_output, exec_info_output]
68
+ )
69
+
70
+ # Launch the Gradio app
71
+ if __name__ == "__main__":
72
+ demo.launch()