Spaces:
Runtime error
Runtime error
Commit
·
dcc0fda
0
Parent(s):
Duplicate from domro11/data_dynamos
Browse files- .gitattributes +35 -0
- README.md +13 -0
- app.py +145 -0
- banner_image.jpg +0 -0
- requirements.txt +6 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
35 |
+
banner_img.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Data Dynamos
|
3 |
+
emoji: 😻
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: blue
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.17.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: domro11/data_dynamos
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from time import sleep
|
3 |
+
from stqdm import stqdm
|
4 |
+
import pandas as pd
|
5 |
+
from transformers import pipeline
|
6 |
+
import json
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
def draw_all(
|
11 |
+
key,
|
12 |
+
plot=False,
|
13 |
+
):
|
14 |
+
st.write(
|
15 |
+
"""
|
16 |
+
# NLP Web App
|
17 |
+
|
18 |
+
This Natural Language Processing Based Web App can do anything u can imagine with Text. 😱
|
19 |
+
|
20 |
+
This App is built using pretrained transformers which are capable of doing wonders with the Textual data.
|
21 |
+
|
22 |
+
```python
|
23 |
+
# Key Features of this App.
|
24 |
+
1. Advanced Text Summarizer
|
25 |
+
2. Sentiment Analysis
|
26 |
+
3. Question Answering
|
27 |
+
4. Text Completion
|
28 |
+
|
29 |
+
```
|
30 |
+
"""
|
31 |
+
)
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
with st.sidebar:
|
36 |
+
draw_all("sidebar")
|
37 |
+
|
38 |
+
|
39 |
+
#main function that holds all the options
|
40 |
+
def main():
|
41 |
+
st.title("NLP IE Web App")
|
42 |
+
menu = ["--Select--","Summarizer",
|
43 |
+
"Sentiment Analysis","Question Answering","Text Completion"]
|
44 |
+
choice = st.sidebar.selectbox("What task would you like to do?", menu)
|
45 |
+
if choice=="--Select--":
|
46 |
+
|
47 |
+
st.write("""
|
48 |
+
|
49 |
+
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
|
50 |
+
do anything with your lectures you like
|
51 |
+
""")
|
52 |
+
|
53 |
+
st.write("""
|
54 |
+
|
55 |
+
Never heard of NLP? No way! Natural Language Processing (NLP) is a computational technique
|
56 |
+
to process human language in all of it's complexity
|
57 |
+
""")
|
58 |
+
|
59 |
+
st.write("""
|
60 |
+
|
61 |
+
NLP is an vital discipline in Artificial Intelligence and keeps growing
|
62 |
+
""")
|
63 |
+
|
64 |
+
|
65 |
+
st.image('banner_image.jpg')
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
elif choice=="Summarizer":
|
70 |
+
st.subheader("Text Summarization")
|
71 |
+
st.write(" Enter the Text you want to summarize !")
|
72 |
+
raw_text = st.text_area("Your Text","Enter Your Text Here")
|
73 |
+
num_words = st.number_input("Enter Number of Words in Summary")
|
74 |
+
|
75 |
+
if raw_text!="" and num_words is not None:
|
76 |
+
num_words = int(num_words)
|
77 |
+
summarizer = pipeline('summarization')
|
78 |
+
summary = summarizer(raw_text, min_length=num_words,max_length=50)
|
79 |
+
s1 = json.dumps(summary[0])
|
80 |
+
d2 = json.loads(s1)
|
81 |
+
result_summary = d2['summary_text']
|
82 |
+
result_summary = '. '.join(list(map(lambda x: x.strip().capitalize(), result_summary.split('.'))))
|
83 |
+
st.write(f"Here's your Summary : {result_summary}")
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
elif choice=="Sentiment Analysis":
|
88 |
+
st.subheader("Sentiment Analysis")
|
89 |
+
#loading the pipeline
|
90 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
91 |
+
st.write(" Enter the Text below To find out its Sentiment !")
|
92 |
+
|
93 |
+
raw_text = st.text_area("Your Text","Enter Text Here")
|
94 |
+
if raw_text !="Enter Text Here":
|
95 |
+
result = sentiment_analysis(raw_text)[0]
|
96 |
+
sentiment = result['label']
|
97 |
+
for _ in stqdm(range(50), desc="Please wait a bit. The model is fetching the results !!"):
|
98 |
+
sleep(0.1)
|
99 |
+
if sentiment =="POSITIVE":
|
100 |
+
st.write("""# This text has a Positive Sentiment. 🤗""")
|
101 |
+
elif sentiment =="NEGATIVE":
|
102 |
+
st.write("""# This text has a Negative Sentiment. 😤""")
|
103 |
+
elif sentiment =="NEUTRAL":
|
104 |
+
st.write("""# This text seems Neutral ... 😐""")
|
105 |
+
|
106 |
+
elif choice=="Question Answering":
|
107 |
+
st.subheader("Question Answering")
|
108 |
+
st.write(" Enter the Context and ask the Question to find out the Answer !")
|
109 |
+
question_answering = pipeline("question-answering")
|
110 |
+
|
111 |
+
|
112 |
+
context = st.text_area("Context","Enter the Context Here")
|
113 |
+
|
114 |
+
#This is the text box for the question
|
115 |
+
question = st.text_area("Your Question","Enter your Question Here")
|
116 |
+
|
117 |
+
if context !="Enter Text Here" and question!="Enter your Question Here":
|
118 |
+
#we are passing question and the context
|
119 |
+
result = question_answering(question=question, context=context)
|
120 |
+
#dump the result in json and load it again
|
121 |
+
s1 = json.dumps(result)
|
122 |
+
d2 = json.loads(s1)
|
123 |
+
generated_text = d2['answer']
|
124 |
+
#joining and capalizing by dot
|
125 |
+
generated_text = '. '.join(list(map(lambda x: x.strip().capitalize(), generated_text.split('.'))))
|
126 |
+
st.write(f" Here's your Answer :\n {generated_text}")
|
127 |
+
|
128 |
+
elif choice=="Text Completion":
|
129 |
+
st.subheader("Text Completion")
|
130 |
+
st.write(" Enter the uncomplete Text to complete it automatically using AI !")
|
131 |
+
text_generation = pipeline("text-generation")
|
132 |
+
message = st.text_area("Your Text","Enter the Text to complete")
|
133 |
+
|
134 |
+
|
135 |
+
if message !="Enter the Text to complete":
|
136 |
+
generator = text_generation(message)
|
137 |
+
s1 = json.dumps(generator[0])
|
138 |
+
d2 = json.loads(s1)
|
139 |
+
generated_text = d2['generated_text']
|
140 |
+
generated_text = '. '.join(list(map(lambda x: x.strip().capitalize(), generated_text.split('.'))))
|
141 |
+
st.write(f" Here's your Generate Text :\n {generated_text}")
|
142 |
+
|
143 |
+
#main function to run
|
144 |
+
if __name__ == '__main__':
|
145 |
+
main()
|
banner_image.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
pandas
|
3 |
+
streamlit
|
4 |
+
stqdm
|
5 |
+
transformers
|
6 |
+
|