Spaces:
Sleeping
Sleeping
update dependences
Browse files- app.py +13 -6
- poetry.lock +0 -0
- pyproject.toml +8 -0
- requirements.txt +6 -1
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
from
|
|
|
|
| 4 |
|
| 5 |
# RU_SUMMARY_MODEL = "IlyaGusev/rubart-large-sum"
|
| 6 |
RU_SUMMARY_MODEL = "IlyaGusev/mbart_ru_sum_gazeta"
|
|
@@ -9,18 +10,24 @@ RU_SENTIMENT_MODEL = "seara/rubert-tiny2-russian-sentiment"
|
|
| 9 |
EN_SUMMARY_MODEL = "sshleifer/distilbart-cnn-12-6"
|
| 10 |
EN_SENTIMENT_MODEL = "ProsusAI/finbert"
|
| 11 |
|
| 12 |
-
class Summarizer(
|
| 13 |
ru_summary_pipe: pipeline
|
| 14 |
ru_sentiment_pipe: pipeline
|
| 15 |
|
| 16 |
def __init__(self) -> None:
|
| 17 |
-
self.ru_summary_pipe = pipeline("summarization", model=RU_SUMMARY_MODEL)
|
| 18 |
-
self.
|
| 19 |
|
| 20 |
def summarize(self, text: str) -> str:
|
| 21 |
result = {}
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return f"Summary: {result['summary']}\n Sentiment:{result['sentiment']}"
|
| 25 |
|
| 26 |
pipe = Summarizer()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from loguru import logger
|
| 4 |
+
# from pydantic import BaseModel
|
| 5 |
|
| 6 |
# RU_SUMMARY_MODEL = "IlyaGusev/rubart-large-sum"
|
| 7 |
RU_SUMMARY_MODEL = "IlyaGusev/mbart_ru_sum_gazeta"
|
|
|
|
| 10 |
EN_SUMMARY_MODEL = "sshleifer/distilbart-cnn-12-6"
|
| 11 |
EN_SENTIMENT_MODEL = "ProsusAI/finbert"
|
| 12 |
|
| 13 |
+
class Summarizer():
|
| 14 |
ru_summary_pipe: pipeline
|
| 15 |
ru_sentiment_pipe: pipeline
|
| 16 |
|
| 17 |
def __init__(self) -> None:
|
| 18 |
+
self.ru_summary_pipe = pipeline("summarization", model=RU_SUMMARY_MODEL, max_length=100, truncation=True)
|
| 19 |
+
self.ru_sentiment_pipe = pipeline("sentiment-analysis", model=RU_SENTIMENT_MODEL)
|
| 20 |
|
| 21 |
def summarize(self, text: str) -> str:
|
| 22 |
result = {}
|
| 23 |
+
response_summary = self.ru_summary_pipe(text)
|
| 24 |
+
logger.info(response_summary)
|
| 25 |
+
result["summary"] = response_summary[0]["summary_text"]
|
| 26 |
+
|
| 27 |
+
response_sentiment = self.ru_sentiment_pipe(text)
|
| 28 |
+
logger.info(response_sentiment)
|
| 29 |
+
result["sentiment"] = response_sentiment[0]["label"]
|
| 30 |
+
|
| 31 |
return f"Summary: {result['summary']}\n Sentiment:{result['sentiment']}"
|
| 32 |
|
| 33 |
pipe = Summarizer()
|
poetry.lock
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
CHANGED
|
@@ -8,6 +8,14 @@ readme = "README.md"
|
|
| 8 |
|
| 9 |
[tool.poetry.dependencies]
|
| 10 |
python = "^3.10"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
[tool.poetry.group.dev.dependencies]
|
|
|
|
| 8 |
|
| 9 |
[tool.poetry.dependencies]
|
| 10 |
python = "^3.10"
|
| 11 |
+
transformers = "^4.36.2"
|
| 12 |
+
gradio = "^4.11.0"
|
| 13 |
+
torch = "1.13.1"
|
| 14 |
+
pydantic = "^2.5.3"
|
| 15 |
+
pretrainedmodels = "^0.7.4"
|
| 16 |
+
sentencepiece = "^0.1.99"
|
| 17 |
+
protobuf = "^4.25.1"
|
| 18 |
+
loguru = "^0.7.2"
|
| 19 |
|
| 20 |
|
| 21 |
[tool.poetry.group.dev.dependencies]
|
requirements.txt
CHANGED
|
@@ -1 +1,6 @@
|
|
| 1 |
-
gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
sentencepiece
|
| 4 |
+
protobuf
|
| 5 |
+
torch==1.13.1
|
| 6 |
+
loguru
|