Vangmayy commited on
Commit
b91c960
·
verified ·
1 Parent(s): 8d610e1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
+ import gradio as gr
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("gpt2")
6
+ model = AutoModelForCausalLM.from_pretrained("Vangmayy/Bollywood-Summary-Generator")
7
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
8
+
9
+ def run_inference(input_text):
10
+ input_text = str(input_text)
11
+ input_ids = tokenizer.encode(input_text, return_tensors = "pt")
12
+ input_ids.to(device)
13
+ new_model = AutoModelForCausalLM.from_pretrained("Vangmayy/Bollywood-Summary-Generator")
14
+ output = new_model.generate(input_ids, max_length = 5000, num_return_sequences = 1)
15
+ output = tokenizer.decode(output[0], skip_special_tokens = True)
16
+ return output
17
+
18
+ genres = ["Action", "Comedy", "Drama", "Horror", "Romance", "Sci-Fi", "Thriller"]
19
+
20
+ with gr.Blocks() as intf:
21
+ gr.Markdown("## Movie Summary Generator")
22
+
23
+ with gr.Row():
24
+ genre_checkboxes = gr.CheckboxGroup(choices=genres, label="Select Genres")
25
+ summary_output = gr.Textbox(label="Generated Summary")
26
+
27
+ generate_button = gr.Button("Generate Summary")
28
+
29
+ def on_click(selected_genres):
30
+ return run_inference(selected_genres)
31
+
32
+ generate_button.click(on_click, inputs=genre_checkboxes, outputs=summary_output)
33
+
34
+ intf.launch()