kinely commited on
Commit
bb56a4a
·
verified ·
1 Parent(s): 80a7732

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+
4
+ url = "https://aspireec.com/"
5
+ response = requests.get(url)
6
+ soup = BeautifulSoup(response.text, 'html.parser')
7
+ # Extract data (e.g., headlines, paragraphs, etc.)
8
+ content = soup.find_all('p') # Example: extracting paragraphs
9
+ website_data = [p.text for p in content]
10
+ import json
11
+
12
+ with open('website_data.json', 'w') as file:
13
+ json.dump(website_data, file)
14
+ from sentence_transformers import SentenceTransformer
15
+
16
+ model = SentenceTransformer('all-MiniLM-L6-v2')
17
+ embeddings = model.encode(website_data)
18
+ import faiss
19
+ import numpy as np
20
+
21
+ # Create FAISS index
22
+ dimension = embeddings.shape[1]
23
+ index = faiss.IndexFlatL2(dimension)
24
+ index.add(np.array(embeddings))
25
+ query = "What is the website about?"
26
+ query_embedding = model.encode([query])
27
+ distances, indices = index.search(np.array(query_embedding), k=1)
28
+ best_match = website_data[indices[0][0]]
29
+ from transformers import pipeline
30
+
31
+ summarizer = pipeline("summarization", model="google/flan-t5-base")
32
+ answer = summarizer(best_match)
33
+ print(answer)
34
+ import streamlit as st
35
+
36
+ st.title("Website Chatbot")
37
+
38
+ user_input = st.text_input("Ask me anything about the website:")
39
+ if user_input:
40
+ response = get_answer(user_input) # Function to query data
41
+ st.write(response)