Spaces:
Sleeping
Sleeping
Commit
·
81762da
1
Parent(s):
f82e1df
Add application file
Browse files- app.py +36 -0
- requirements.txt +111 -0
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the sentiment analysis, keyword extraction, and text summarization models from Hugging Face
|
| 5 |
+
sentiment_model = pipeline("sentiment-analysis")
|
| 6 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 7 |
+
keyword_extraction_model = pipeline(
|
| 8 |
+
"text2text-generation", model="transformer3/keywordextractor"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Define the function to be called when text input is provided
|
| 13 |
+
def analyze_text(text):
|
| 14 |
+
# Sentiment analysis
|
| 15 |
+
sentiment_result = sentiment_model(text)[0]
|
| 16 |
+
sentiment = sentiment_result["label"]
|
| 17 |
+
sentiment_score = sentiment_result["score"]
|
| 18 |
+
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 19 |
+
|
| 20 |
+
# Keyword extraction
|
| 21 |
+
keyword_result = keyword_extraction_model(
|
| 22 |
+
f"summarize: {text}", max_length=50, num_return_sequences=1
|
| 23 |
+
)
|
| 24 |
+
keywords = keyword_result[0]
|
| 25 |
+
|
| 26 |
+
# # Text summarization
|
| 27 |
+
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 28 |
+
|
| 29 |
+
return f"Sentiment: {sentiment}, Score: {sentiment_score}\nKeywords: {keywords}\nSummary: {summary}"
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# Create the Gradio interface
|
| 33 |
+
iface = gr.Interface(fn=analyze_text, inputs="text", outputs="text")
|
| 34 |
+
|
| 35 |
+
# Launch the interface
|
| 36 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiofiles==23.1.0
|
| 2 |
+
aiohttp==3.8.4
|
| 3 |
+
aiosignal==1.3.1
|
| 4 |
+
altair==5.0.0
|
| 5 |
+
anyio==3.6.2
|
| 6 |
+
appdirs==1.4.4
|
| 7 |
+
asttokens==2.2.1
|
| 8 |
+
async-timeout==4.0.2
|
| 9 |
+
attrs==23.1.0
|
| 10 |
+
audioread==3.0.0
|
| 11 |
+
backcall==0.2.0
|
| 12 |
+
certifi==2023.5.7
|
| 13 |
+
cffi==1.15.1
|
| 14 |
+
charset-normalizer==3.1.0
|
| 15 |
+
click==8.1.3
|
| 16 |
+
colorama==0.4.6
|
| 17 |
+
contourpy==1.0.7
|
| 18 |
+
cycler==0.11.0
|
| 19 |
+
decorator==5.1.1
|
| 20 |
+
dill==0.3.6
|
| 21 |
+
executing==1.2.0
|
| 22 |
+
fastapi==0.95.2
|
| 23 |
+
ffmpy==0.3.0
|
| 24 |
+
filelock==3.12.0
|
| 25 |
+
fonttools==4.39.4
|
| 26 |
+
frozenlist==1.3.3
|
| 27 |
+
fsspec==2023.5.0
|
| 28 |
+
gradio==3.32.0
|
| 29 |
+
gradio_client==0.2.5
|
| 30 |
+
h11==0.14.0
|
| 31 |
+
httpcore==0.17.1
|
| 32 |
+
httpx==0.24.1
|
| 33 |
+
huggingface-hub==0.14.1
|
| 34 |
+
idna==3.4
|
| 35 |
+
ipython==7.12.0
|
| 36 |
+
jedi==0.18.2
|
| 37 |
+
Jinja2==3.1.2
|
| 38 |
+
joblib==1.2.0
|
| 39 |
+
jsonschema==4.17.3
|
| 40 |
+
kiwisolver==1.4.4
|
| 41 |
+
lazy_loader==0.2
|
| 42 |
+
librosa==0.10.0.post2
|
| 43 |
+
linkify-it-py==2.0.2
|
| 44 |
+
llvmlite==0.40.0
|
| 45 |
+
markdown-it-py==2.2.0
|
| 46 |
+
MarkupSafe==2.1.2
|
| 47 |
+
matplotlib==3.7.1
|
| 48 |
+
matplotlib-inline==0.1.6
|
| 49 |
+
mdit-py-plugins==0.3.3
|
| 50 |
+
mdurl==0.1.2
|
| 51 |
+
mpmath==1.3.0
|
| 52 |
+
msgpack==1.0.5
|
| 53 |
+
multidict==6.0.4
|
| 54 |
+
multiprocess==0.70.14
|
| 55 |
+
networkx==3.1
|
| 56 |
+
numba==0.57.0
|
| 57 |
+
numpy==1.24.3
|
| 58 |
+
orjson==3.8.12
|
| 59 |
+
packaging==23.1
|
| 60 |
+
pandas==2.0.1
|
| 61 |
+
parso==0.8.3
|
| 62 |
+
pickleshare==0.7.5
|
| 63 |
+
Pillow==9.5.0
|
| 64 |
+
pip==22.3.1
|
| 65 |
+
pooch==1.6.0
|
| 66 |
+
prompt-toolkit==3.0.38
|
| 67 |
+
pure-eval==0.2.2
|
| 68 |
+
pyarrow==12.0.0
|
| 69 |
+
pycparser==2.21
|
| 70 |
+
pydantic==1.10.7
|
| 71 |
+
pydub==0.25.1
|
| 72 |
+
Pygments==2.15.1
|
| 73 |
+
pyparsing==3.0.9
|
| 74 |
+
pyrsistent==0.19.3
|
| 75 |
+
python-dateutil==2.8.2
|
| 76 |
+
python-multipart==0.0.6
|
| 77 |
+
pytz==2023.3
|
| 78 |
+
PyYAML==6.0
|
| 79 |
+
requests==2.30.0
|
| 80 |
+
responses==0.18.0
|
| 81 |
+
scikit-learn==1.2.2
|
| 82 |
+
scipy==1.10.1
|
| 83 |
+
semantic-version==2.10.0
|
| 84 |
+
setuptools==65.5.0
|
| 85 |
+
six==1.16.0
|
| 86 |
+
sniffio==1.3.0
|
| 87 |
+
sounddevice==0.4.6
|
| 88 |
+
soundfile==0.12.1
|
| 89 |
+
soxr==0.3.5
|
| 90 |
+
SpeechRecognition==3.10.0
|
| 91 |
+
stack-data==0.6.2
|
| 92 |
+
starlette==0.27.0
|
| 93 |
+
sympy==1.12
|
| 94 |
+
threadpoolctl==3.1.0
|
| 95 |
+
tokenizers==0.13.3
|
| 96 |
+
toolz==0.12.0
|
| 97 |
+
torch==2.0.1
|
| 98 |
+
torchaudio==2.0.2
|
| 99 |
+
torchvision==0.15.2
|
| 100 |
+
tqdm==4.65.0
|
| 101 |
+
traitlets==5.9.0
|
| 102 |
+
transformers==4.29.2
|
| 103 |
+
typing_extensions==4.5.0
|
| 104 |
+
tzdata==2023.3
|
| 105 |
+
uc-micro-py==1.0.2
|
| 106 |
+
urllib3==2.0.2
|
| 107 |
+
uvicorn==0.22.0
|
| 108 |
+
wcwidth==0.2.6
|
| 109 |
+
websockets==11.0.3
|
| 110 |
+
xxhash==3.2.0
|
| 111 |
+
yarl==1.9.2
|