asFrants commited on
Commit
2a3c4ce
1 Parent(s): 24fbc89

first pipes

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -1,10 +1,32 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!"
 
 
 
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  demo = gr.Interface(
7
- fn=greet,
8
  inputs=gr.Textbox(lines=5, placeholder="Write your text here..."),
9
  outputs=gr.Textbox(lines=5, placeholder="Summary and Sentiment would be here..."),
10
  )
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ from pydantic import BaseModel
4
 
5
+ # RU_SUMMARY_MODEL = "IlyaGusev/rubart-large-sum"
6
+ RU_SUMMARY_MODEL = "IlyaGusev/mbart_ru_sum_gazeta"
7
+ # RU_SENTIMENT_MODEL = "IlyaGusev/rubart-large-sentiment"
8
+ 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(BaseModel):
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.ru_summary_pipe = pipeline("sentiment-analysis", model=RU_SENTIMENT_MODEL)
19
+
20
+ def summarize(self, text: str) -> str:
21
+ result = {}
22
+ result["summary"] = self.ru_summary_pipe(text)[0]["label"]
23
+ result["sentiment"] = self.ru_sentiment_pipe(text)[0]["label"]
24
+ return f"Summary: {result['summary']}\n Sentiment:{result['sentiment']}"
25
+
26
+ pipe = Summarizer()
27
+
28
  demo = gr.Interface(
29
+ fn=pipe.summarize,
30
  inputs=gr.Textbox(lines=5, placeholder="Write your text here..."),
31
  outputs=gr.Textbox(lines=5, placeholder="Summary and Sentiment would be here..."),
32
  )