Spaces:
Build error
Build error
File size: 5,525 Bytes
b18868d 11b96a3 b18868d 971925a 6a97837 11b96a3 b18868d 216fb76 b18868d ae4ac63 b18868d ae4ac63 b18868d 48d4c25 b18868d 216fb76 b18868d 6d55e84 53afcf4 5aa077f 6f3fdbc 216fb76 b18868d 216fb76 b18868d ae4ac63 971925a ae4ac63 971925a 514c688 971925a b18868d 971925a |
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
import streamlit as st
from time import sleep
from stqdm import stqdm
import pandas as pd
from transformers import pipeline
import json
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
def draw_all(
key,
plot=False,
):
st.write(
"""
# NLP Web App
This Natural Language Processing Based Web App can do anything u can imagine with Text. 😱
This App is built using pretrained transformers which are capable of doing wonders with the Textual data.
```python
# Key Features of this App.
1. Advanced Text Summarizer
2. Key Word Extractor
3. Question Answering
4. Question Generation
```
"""
)
with st.sidebar:
draw_all("sidebar")
#main function that holds all the options
def main():
st.title("NLP IE Web App")
menu = ["--Select--","Summarizer",
"Keyword Extractor","Question Answering","Question Generation"]
choice = st.sidebar.selectbox("What task would you like to do?", menu)
if choice=="--Select--":
st.write("""
Welcome to the the Web App of Data Dynamos. As an IE student of the Master of Business Analyitics and Big Data you have the opportunity to
do anything with your lectures you like
""")
st.write("""
Never heard of NLP? No way! Natural Language Processing (NLP) is a computational technique
to process human language in all of it's complexity
""")
st.write("""
NLP is an vital discipline in Artificial Intelligence and keeps growing
""")
st.image('banner_image.jpg')
elif choice=="Summarizer":
st.subheader("Text Summarization")
st.write(" Enter the Text you want to summarize !")
raw_text = st.text_area("Your Text","Enter Your Text Here")
num_words = st.number_input("Enter Number of Words in Summary")
if raw_text!="" and num_words is not None:
num_words = int(num_words)
summarizer = pipeline('summarization')
summary = summarizer(raw_text, min_length=num_words,max_length=50)
s1 = json.dumps(summary[0])
d2 = json.loads(s1)
result_summary = d2['summary_text']
result_summary = '. '.join(list(map(lambda x: x.strip().capitalize(), result_summary.split('.'))))
st.write(f"Here's your Summary : {result_summary}")
elif choice=="Keyword Extractor":
st.subheader("Keyword Extraction")
#loading the pipeline
model_name = "yanekyuk/bert-uncased-keyword-extractor"
keyword_extractor = pipeline("text2text-generation", model=model_name, tokenizer=model_name)
input_text = st.text_area("Enter some text:")
if st.button("Extract Keywords"):
# Extract keywords using the model
keywords = keyword_extractor(input_text, max_length=20, do_sample=False)[0]["generated_text"]
# Display the extracted keywords
st.write("Keywords:", keywords)
elif choice=="Question Answering":
st.subheader("Question Answering")
st.write(" Enter the Context and ask the Question to find out the Answer !")
question_answering = pipeline("question-answering", model = "distilbert-base-cased-distilled-squad")
context = st.text_area("Context","Enter the Context Here")
#This is the text box for the question
question = st.text_area("Your Question","Enter your Question Here")
if context !="Enter Text Here" and question!="Enter your Question Here":
#we are passing question and the context
result = question_answering(question=question, context=context)
#dump the result in json and load it again
s1 = json.dumps(result)
d2 = json.loads(s1)
generated_text = d2['answer']
#joining and capalizing by dot
generated_text = '. '.join(list(map(lambda x: x.strip().capitalize(), generated_text.split('.'))))
st.write(f" Here's your Answer :\n {generated_text}")
elif choice=="Question Generation":
st.subheader("Question Generation")
st.write(" Enter the text to get questions generated !")
# Load the T5 model and tokenizer
model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
text_input2 = st.text_area("Your Text","Enter the Text to complete")
# Create a button to generate questions
if st.button("Generate Questions"):
#Encode the input text using the tokenizer
input_ids = tokenizer.encode("generate questions: " + text_input2, return_tensors="pt")
# Use the T5 model to generate questions
question_ids = model.generate(input_ids)
# Decode the questions from the output ids using the tokenizer
questions = tokenizer.decode(question_ids[0], skip_special_tokens=True)
# Display the questions to the user
st.write(questions)
#main function to run
if __name__ == '__main__':
main()
|