File size: 2,786 Bytes
3bf5431
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b21a8bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import streamlit as st
import transformers
# import streamlit.components.v1 as components
import tensorflow as tf
from transformers import pipeline
import pandas as pd
# Web Scrapping packages
import bs4
from bs4 import BeautifulSoup#pip install bs4
from urllib.request import urlopen

favicon= "articulate_favicon.ico"
st.set_page_config(
    page_title="Articulate by ParthRangarajan",
    page_icon=favicon,
    layout="wide",
    initial_sidebar_state="expanded"
)

# loading the model
@st.cache(allow_output_mutation=True)#keeps up high performance
def load_model():
    model= pipeline("question-answering")
    return model

qa_model= load_model()

# def get_text(url):
#     page = urlopen(url)
#     soup = BeautifulSoup(page)
#     fetched_text = ' '.join(map(lambda p:p.text, soup.find_all('p')))
#     return fetched_text



# url = 'https://www.troyhunt.com/the-773-million-record-collection-1-data-reach/'


st.header("Welcome to Articulate!")
st.title("Have questions based on an article?")
# text area
article= st.text_area("Enter the article here!")
url_toopen= st.text_input("Or enter your article URL here!")
question_asked= st.text_input("Ask your questions here!")
button= st.button("Search Answer")

def url_article():
    page = urlopen(url_toopen)
    soup = BeautifulSoup(page)
    fetched_text = ' '.join(map(lambda p: p.text, soup.find_all('p')))
    return fetched_text

with st.spinner("Searching for your answers... This could take a while πŸ™ƒ"):
    try:
        if button and article:
            answers= qa_model(question= question_asked, context= article)
            st.success(answers['answer'])
            # st.balloons()
        elif button and url_toopen:
            ans = url_article()
            answers = qa_model(question=question_asked, context=ans)
            st.success(answers['answer'])
            # st.balloons()
    except ValueError:
        st.error('😞 Oops! Something went wrong. Please try again.')

# st.title("Examples")
# st.text("What is this article about?")
example_df=pd.DataFrame(["What is this article about ?", "What are the types of ___ ?", "What is the application of machine learning ?"], columns=["Examples"])
st.dataframe(example_df)



footer="""<style>
a:link , a:visited{
color: blue;
background-color: transparent;
text-decoration: underline;
}

a:hover,  a:active {
color: red;
background-color: transparent;
text-decoration: underline;
}

.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: black;
color: white;
text-align: center;
}
</style>
<div class="footer">
<p>Developed by <a style='display: block; text-align: center;color: "red"' href="https://github.com/parthrangarajan" target="_blank">Parth Rangarajan</a></p>
</div>
"""
st.markdown(footer,unsafe_allow_html=True)