RickyMartin-dev commited on
Commit
7bae4d1
1 Parent(s): 6fc9f86

First Push

Browse files
Files changed (2) hide show
  1. app.py +64 -0
  2. requirements.txt +85 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Building a Question and Answering Application using HuggingFace models
2
+ # And the Streamlit library
3
+
4
+ # Imports
5
+ import torch
6
+ import wikipedia
7
+ import transformers
8
+ import streamlit as st
9
+ from transformers import pipeline, Pipeline
10
+
11
+ # Helper Functions
12
+ # Loads Summary of Topic From WikiPedia
13
+ def load_wiki_summary(query:str) -> str:
14
+ results = wikipedia.search(query)
15
+ summary = wikipedia.summary(results[0], sentences=10)
16
+ return summary
17
+
18
+ # Load Question and Answering Bert Pipeline
19
+ def load_qa_pipeline() -> Pipeline:
20
+ qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
21
+ return qa_pipeline
22
+
23
+ # Answer the question given the pipeline input
24
+ def answer_question(pipeline:Pipeline, question:str, paragraph:str) -> dict:
25
+ input = {
26
+ "question":question,
27
+ "context":paragraph
28
+ }
29
+ output = pipeline(input)
30
+ return output
31
+
32
+ # Main app
33
+ if __name__ == "__main__":
34
+ # Display title and description
35
+ st.title("Wikipedia Question Answering")
36
+ st.write("Search a topic, Ask a Questions, and Get Answers!!")
37
+
38
+ # Display Topic input slot
39
+ topic = st.text_input("SEARCH TOPIC", "")
40
+
41
+ # Display article paragraph
42
+ article_paragraph = st.empty()
43
+
44
+ # Display questino input slot
45
+ question = st.text_input("QUESTON", "")
46
+
47
+ if topic:
48
+ # load wikipedia summary of topic
49
+ summary = load_wiki_summary(topic)
50
+
51
+ # Display
52
+ article_paragraph.markdown(summary)
53
+
54
+ # Perform Question Answering
55
+ if question != "":
56
+ # Load Question Answering Pipeline
57
+ qa_pipeline = load_qa_pipeline()
58
+
59
+ # Answer Query Question using article Summary
60
+ result = answer_question(qa_pipeline, question, summary)
61
+ answer = result["answer"]
62
+
63
+ # display answer
64
+ st.write(answer)
requirements.txt ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohttp==3.8.4
2
+ aiosignal==1.3.1
3
+ altair==5.0.1
4
+ async-timeout==4.0.2
5
+ attrs==23.1.0
6
+ beautifulsoup4==4.12.2
7
+ blinker==1.6.2
8
+ cachetools==5.3.1
9
+ certifi==2023.5.7
10
+ charset-normalizer==3.1.0
11
+ click==8.1.3
12
+ dataclasses-json==0.5.7
13
+ decorator==5.1.1
14
+ filelock==3.12.2
15
+ Flask==2.3.2
16
+ frozenlist==1.3.3
17
+ fsspec==2023.5.0
18
+ gitdb==4.0.10
19
+ GitPython==3.1.31
20
+ gunicorn==20.1.0
21
+ huggingface-hub==0.15.1
22
+ idna==3.4
23
+ importlib-metadata==6.7.0
24
+ itsdangerous==2.1.2
25
+ Jinja2==3.1.2
26
+ jsonschema==4.17.3
27
+ langchain==0.0.181
28
+ llama-index==0.6.12
29
+ markdown-it-py==3.0.0
30
+ MarkupSafe==2.1.2
31
+ marshmallow==3.19.0
32
+ marshmallow-enum==1.5.1
33
+ mdurl==0.1.2
34
+ mpmath==1.3.0
35
+ multidict==6.0.4
36
+ mypy-extensions==1.0.0
37
+ networkx==3.1
38
+ numexpr==2.8.4
39
+ numpy==1.24.3
40
+ openai==0.27.7
41
+ openapi-schema-pydantic==1.2.4
42
+ packaging==23.1
43
+ pandas==2.0.1
44
+ Pillow==9.5.0
45
+ protobuf==4.23.3
46
+ pyarrow==12.0.1
47
+ pydantic==1.10.8
48
+ pydeck==0.8.1b0
49
+ Pygments==2.15.1
50
+ Pympler==1.0.1
51
+ pypdf==3.9.0
52
+ pyrsistent==0.19.3
53
+ python-dateutil==2.8.2
54
+ pytz==2023.3
55
+ pytz-deprecation-shim==0.1.0.post0
56
+ PyYAML==6.0
57
+ regex==2023.5.5
58
+ requests==2.31.0
59
+ rich==13.4.2
60
+ safetensors==0.3.1
61
+ six==1.16.0
62
+ smmap==5.0.0
63
+ soupsieve==2.4.1
64
+ SQLAlchemy==2.0.15
65
+ streamlit==1.23.1
66
+ sympy==1.12
67
+ tenacity==8.2.2
68
+ tiktoken==0.4.0
69
+ tokenizers==0.13.3
70
+ toml==0.10.2
71
+ toolz==0.12.0
72
+ torch==2.0.1
73
+ tornado==6.3.2
74
+ tqdm==4.65.0
75
+ transformers==4.30.2
76
+ typing-inspect==0.8.0
77
+ typing_extensions==4.5.0
78
+ tzdata==2023.3
79
+ tzlocal==4.3
80
+ urllib3==1.26.16
81
+ validators==0.20.0
82
+ Werkzeug==2.3.4
83
+ wikipedia==1.4.0
84
+ yarl==1.9.2
85
+ zipp==3.15.0