PSM24 KayO commited on
Commit
cf543aa
0 Parent(s):

Duplicate from KayO/Webpage-Question-Answering

Browse files

Co-authored-by: Kwadwo Agyapon-Ntra <KayO@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +46 -0
  4. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Webpage Question Answering
3
+ emoji: ❓
4
+ colorFrom: pink
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 3.11.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ duplicated_from: KayO/Webpage-Question-Answering
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
+ from transformers import pipeline
5
+
6
+ # Load the trained model
7
+ qa_model = pipeline("question-answering")
8
+
9
+ def extract_answer(question, url):
10
+ """Get context from URL and use it to answer the question"""
11
+
12
+ # Retrieve actual page content
13
+ html = requests.get(url).content
14
+ # Create BS4 object to handle HTML data
15
+ soup = BeautifulSoup(html, 'html.parser')
16
+
17
+ for data in soup(['style', 'script', 'meta', 'link', 'noscript']):
18
+ # Remove tags
19
+ data.decompose()
20
+
21
+ # Get and clean up plain text
22
+ context = soup.get_text()
23
+ while "\n\n" in context:
24
+ context = context.replace("\n\n", "\n")
25
+
26
+ answer_dict = qa_model(question = question, context = context)
27
+ return answer_dict
28
+
29
+
30
+ title = "Webpage-Based Question Answering"
31
+ description = "Using a webpage as context for extractive question answering."
32
+ enable_queue=True
33
+ examples=[
34
+ ["Where was Messi born?", "https://en.wikipedia.org/wiki/Lionel_Messi"],
35
+ ["When was Cristiano Ronaldo born?", "https://en.wikipedia.org/wiki/Cristiano_Ronaldo"]
36
+ ]
37
+
38
+ iface = gr.Interface(
39
+ fn=extract_answer,
40
+ inputs=["text", "text"],
41
+ outputs="text",
42
+ title=title,
43
+ description=description,
44
+ examples=examples
45
+ )
46
+ iface.launch(enable_queue=enable_queue)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers[torch]
2
+ beautifulsoup4