Spaces:
Sleeping
Sleeping
File size: 780 Bytes
0f40b7f ee6d076 589a85d 0f40b7f 4d65f0c 9499279 92d0083 9499279 ee6d076 40276b8 589a85d ee6d076 9499279 ee6d076 9499279 98d221b 28d9783 9499279 | 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 | import gradio as gr
import torch
from transformers import T5ForConditionalGeneration, T5Tokenizer
model_id = "amielitos/text-to-markdown-t5"
tokenizer = T5Tokenizer.from_pretrained(model_id)
model = T5ForConditionalGeneration.from_pretrained(model_id)
def predict(input_text):
# Match the prefix used in training
prompt = f"format md: {input_text}"
inputs = tokenizer(prompt, return_tensors="pt").input_ids
# beam_search + penalty = better guessing
outputs = model.generate(
inputs,
max_length=256,
num_beams=5,
repetition_penalty=3.0,
early_stopping=True
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
demo = gr.Interface(fn=predict, inputs="text", outputs="markdown")
demo.launch() |