Spaces:
Runtime error
Runtime error
File size: 1,061 Bytes
65b0852 47a98d3 65b0852 |
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 30 31 32 33 34 35 36 37 38 |
import torch
from transformers import T5Tokenizer, T5ForConditionalGeneration
from transformers.optimization import Adafactor
import time
import warnings
model = T5ForConditionalGeneration.from_pretrained('pytoch_model.bin', return_dict=True,config='t5-base-config.json')
def generate(text):
model.eval()
input_ids = tokenizer.encode("WebNLG:{} </s>".format(text), return_tensors="pt") # Batch size 1
# input_ids.to(dev)
s = time.time()
outputs = model.generate(input_ids)
gen_text=tokenizer.decode(outputs[0]).replace('<pad>','').replace('</s>','')
elapsed = time.time() - s
print('Generated in {} seconds'.format(str(elapsed)[:4]))
return gen_text
import gradio as gr
# Define the Gradio interface
iface = gr.Interface(
fn=generate, # Replace with your actual function
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
outputs=gr.outputs.Textbox(),
title="Text Generation App",
description="Enter some text and see the generated output.",
)
# Launch the Gradio interface
iface.launch()
|