Razavipour commited on
Commit
b041efd
·
verified ·
1 Parent(s): 8dc154b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import LEDForConditionalGeneration, LEDTokenizer
3
+ import torch
4
+
5
+ # Load the model and tokenizer
6
+ model = LEDForConditionalGeneration.from_pretrained("./summary_generation_led_4")
7
+ tokenizer = LEDTokenizer.from_pretrained("./summary_generation_led_4")
8
+
9
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
10
+ model = model.to(device)
11
+
12
+ # Define the function for generating summaries
13
+ def generate_summary(plot_synopsis):
14
+ inputs = tokenizer(plot_synopsis, max_length=3000, truncation=True, padding="max_length", return_tensors="pt")
15
+ inputs = inputs.to(device)
16
+ outputs = model.generate(inputs['input_ids'], max_length=315, min_length=20, length_penalty=2.0, num_beams=4, early_stopping=True)
17
+ summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+ return summary
19
+
20
+ # Create a Gradio interface
21
+ interface = gr.Interface(fn=generate_summary,
22
+ inputs=gr.Textbox(label="Plot Synopsis", lines=10, placeholder="Enter plot synopsis here..."),
23
+ outputs=gr.Textbox(label="Plot Summary"),
24
+ title="Plot Summary Generator",
25
+ description="This demo generates a plot summary based on a plot synopsis using a fine-tuned LED model.")
26
+
27
+ # Launch the interface
28
+ interface.launch()