asritha22bce commited on
Commit
07aece2
·
verified ·
1 Parent(s): bd79a17

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
+
4
+ # Load model and tokenizer from Hugging Face
5
+ model = AutoModelForSeq2SeqLM.from_pretrained("your-hf-username/bart-positive-tone-finetuned")
6
+ tokenizer = AutoTokenizer.from_pretrained("your-hf-username/bart-positive-tone-finetuned")
7
+
8
+ # Function to process headlines
9
+ def neutralize_headline(headline):
10
+ inputs = tokenizer(headline, return_tensors="pt", truncation=True, padding=True)
11
+ outputs = model.generate(**inputs)
12
+ neutralized_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+ return neutralized_text
14
+
15
+ # Create Gradio UI
16
+ iface = gr.Interface(
17
+ fn=neutralize_headline,
18
+ inputs=gr.Textbox(lines=2, placeholder="Enter a negative/extreme headline..."),
19
+ outputs="text",
20
+ title="Headline Neutralizer",
21
+ description="Converts extreme headlines into a neutral tone.",
22
+ )
23
+
24
+ iface.launch()