Naman Pundir commited on
Commit
f658876
·
1 Parent(s): 982131a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -1,14 +1,25 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
- from transformers import GPT2LMHeadModel, GPT2Config
5
-
6
- model_name = "facebook/bart-large-cnn"
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
 
 
 
 
 
 
9
 
10
  # Define the Gradio interface
11
- def summarize_text(input_text):
 
 
 
 
 
12
  # Tokenize and generate summary
13
  input_ids = tokenizer.encode(input_text, return_tensors="pt", max_length=1024, truncation=True)
14
  summary_ids = model.generate(input_ids, max_length=10, min_length=1, length_penalty=1.0, num_beams=4, early_stopping=True)
@@ -17,11 +28,11 @@ def summarize_text(input_text):
17
 
18
  iface = gr.Interface(
19
  fn=summarize_text,
20
- inputs="text",
21
  outputs="text",
22
- title="Concept Tagger",
23
- description="Concept tag your text using Theus model (1.3B Concept Tagging).",
24
  )
25
 
26
  if __name__ == "__main__":
27
- iface.launch()
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
+ # Define the models and their corresponding names
5
+ models = {
6
+ "Model 1 (facebook/bart-large-cnn)": {
7
+ "model_name": "facebook/bart-large-cnn",
8
+ "description": "Model 1",
9
+ },
10
+ "Model 2 ()": {
11
+ "model_name": "google/pegasus-multi_news",
12
+ "description": "Model 2",
13
+ },
14
+ }
15
 
16
  # Define the Gradio interface
17
+ def summarize_text(input_text, selected_model):
18
+ # Get the selected model and its tokenizer
19
+ model_info = models[selected_model]
20
+ tokenizer = AutoTokenizer.from_pretrained(model_info["model_name"])
21
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_info["model_name"])
22
+
23
  # Tokenize and generate summary
24
  input_ids = tokenizer.encode(input_text, return_tensors="pt", max_length=1024, truncation=True)
25
  summary_ids = model.generate(input_ids, max_length=10, min_length=1, length_penalty=1.0, num_beams=4, early_stopping=True)
 
28
 
29
  iface = gr.Interface(
30
  fn=summarize_text,
31
+ inputs=[gr.inputs.Textbox(label="Input Text"), gr.inputs.Radio(model_names, label="Select Model")],
32
  outputs="text",
33
+ title="Text Summarization App",
34
+ description="Choose a model for text summarization and enter the text to summarize.",
35
  )
36
 
37
  if __name__ == "__main__":
38
+ iface.launch()