File size: 1,109 Bytes
26628e2
b0d9d1f
ab0c22f
26628e2
 
697b008
26628e2
697b008
26628e2
 
e5f9d0d
26628e2
 
 
 
 
 
e5f9d0d
26628e2
 
11d5370
26628e2
 
 
 
 
848f38c
26628e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Step 2: Install the latest version of Gradio
#!pip install gradio

# Step 3: Verify the installation
import gradio as gr

print("Gradio version:", gr.__version__)

# Step 4: Define the Gradio interface using the latest API
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

def summarize(text):
    tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn")
    model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn")
    inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
    summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
    return tokenizer.decode(summary_ids[0], skip_special_tokens=True)

iface1 = gr.Interface(fn=summarize, inputs="textbox", outputs="textbox", title="Text Summarizer")
iface2 = gr.Interface(fn=summarize, inputs="textbox", outputs="textbox", title="Text Summarizer")

# Combine interfaces using the latest Gradio Blocks API
with gr.Blocks() as demo:
    with gr.Row():
        iface1.render()
        

demo.launch()