Spaces:
Runtime error
Runtime error
YassineToughrai
commited on
Commit
•
c46f9c8
1
Parent(s):
0ccd6e3
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Compréhension et génération de titres.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1YuQqHgbE4limD6MH0CTuTjRq-f93ZRcX
|
8 |
+
"""
|
9 |
+
|
10 |
+
import torch
|
11 |
+
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
12 |
+
|
13 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
+
|
15 |
+
model = T5ForConditionalGeneration.from_pretrained("Michau/t5-base-en-generate-headline")
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained("t5-base")
|
17 |
+
model = model.to(device)
|
18 |
+
"""
|
19 |
+
Very early yesterday morning, the United States President Donald Trump reported he and his wife First Lady Melania Trump tested positive for COVID-19. Officials said the Trumps' 14-year-old son Barron tested negative as did First Family and Senior Advisors Jared Kushner and Ivanka Trump.
|
20 |
+
Trump took to social media, posting at 12:54 am local time (0454 UTC) on Twitter, "Tonight, [Melania] and I tested positive for COVID-19. We will begin our quarantine and recovery process immediately. We will get through this TOGETHER!" Yesterday afternoon Marine One landed on the White House's South Lawn flying Trump to Walter Reed National Military Medical Center (WRNMMC) in Bethesda, Maryland.
|
21 |
+
Reports said both were showing "mild symptoms". Senior administration officials were tested as people were informed of the positive test. Senior advisor Hope Hicks had tested positive on Thursday.
|
22 |
+
Presidential physician Sean Conley issued a statement saying Trump has been given zinc, vitamin D, Pepcid and a daily Aspirin. Conley also gave a single dose of the experimental polyclonal antibodies drug from Regeneron Pharmaceuticals.
|
23 |
+
According to official statements, Trump, now operating from the WRNMMC, is to continue performing his duties as president during a 14-day quarantine. In the event of Trump becoming incapacitated, Vice President Mike Pence could take over the duties of president via the 25th Amendment of the US Constitution. The Pence family all tested negative as of yesterday and there were no changes regarding Pence's campaign events.
|
24 |
+
"""
|
25 |
+
|
26 |
+
|
27 |
+
import gradio as gr
|
28 |
+
|
29 |
+
def generate_headline(article):
|
30 |
+
text = "headline: " + article
|
31 |
+
text
|
32 |
+
max_len = 256
|
33 |
+
|
34 |
+
encoding = tokenizer.encode_plus(text, return_tensors = "pt")
|
35 |
+
input_ids = encoding["input_ids"].to(device)
|
36 |
+
attention_masks = encoding["attention_mask"].to(device)
|
37 |
+
|
38 |
+
beam_outputs = model.generate(
|
39 |
+
input_ids = input_ids,
|
40 |
+
attention_mask = attention_masks,
|
41 |
+
max_length = 64,
|
42 |
+
num_beams = 3,
|
43 |
+
early_stopping = True,
|
44 |
+
)
|
45 |
+
|
46 |
+
result = tokenizer.decode(beam_outputs[0])
|
47 |
+
result = result.lstrip('<pad>')
|
48 |
+
result = result.rstrip('</s>')
|
49 |
+
return result
|
50 |
+
|
51 |
+
demo = gr.Interface(fn=generate_headline, inputs="text", outputs="text")
|
52 |
+
demo.launch()
|
53 |
+
|