File size: 1,949 Bytes
c3b5289
61e2838
c67ac6c
 
 
61e2838
 
 
 
c67ac6c
 
 
 
c3b5289
 
 
61e2838
 
3578aec
 
 
 
 
 
603e12c
c67ac6c
 
61e2838
c3b5289
 
 
890ecd0
c3b5289
c67ac6c
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
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration
from transformers import pipeline

pipe = pipeline(model="facebook/bart-large-mnli")

tokenizer = T5Tokenizer.from_pretrained("./model_files")
model = T5ForConditionalGeneration.from_pretrained("./model_files")

examples = [
    "Saurav Kant, an alumnus of upGrad and  upGrad learner switches to career in ML & Al with 90% IIIT-B's PG Program in Machine learning and Artificial  salary hike  Intelligence, was a Sr Systems Engineer at Infosys with almost 5 years of work experience. The program and  upGrad's 360-degree career support helped him  transition to a Data Scientist at Tech Mahindra with  90% salary hike. upGrad's Online Power Learning has powered 3 lakh+ careers.",
    "Kunal Shah's credit card bill payment platform, CRED, gave users a chance to win free food from Swiggy for one year. Pranav Kaushik, a Delhi techie, bagged this reward after spending 2000 CRED coins. Users get one CRED coin per rupee of bill paid, which can be used to avail rewards from brands like Ixigo, BookMyShow, UberEats, Cult.Fit and more."
]


def greet(name):
    inp =  "Summarize:" + name
    input_ids = tokenizer(inp, return_tensors="pt").input_ids
    outputs = model.generate(input_ids,
                             max_length=150, 
                             num_beams=2,
                             repetition_penalty=2.5, 
                             length_penalty=1.0, 
                             early_stopping=True)
    fin = tokenizer.decode(outputs[0],skip_special_tokens=True, clean_up_tokenization_spaces=True)
    res = pipe(str(fin),candidate_labels=["bearish", "neutral", "bullish"],)
    return str(fin),str(res['labels'][0])
    


# We instantiate the Textbox class
textbox = gr.Textbox(label="Enter your article:", placeholder="Article", lines=5)

gr.Interface(fn=greet, inputs=textbox, outputs=["text","text"], examples=examples).launch()