Spaces:
Build error
Build error
| import gradio as gr | |
| from gradio import mix | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| from huggingface_hub import from_pretrained_keras | |
| title = "Miniature" | |
| description = "Gradio Demo for a miniature with GPT. To use it, simply add your text, or click one of the examples to load them. Read more at the links below." | |
| tokenizer = AutoTokenizer.from_pretrained("aditi2222/automatic_title_generation") | |
| model = from_pretrained_keras("keras-io/text-generation-miniature-gpt") | |
| def tokenize_data(text): | |
| # Tokenize the review body | |
| input_ = str(text) + ' </s>' | |
| max_len = 120 | |
| # tokenize inputs | |
| tokenized_inputs = tokenizer(input_, padding='max_length', truncation=True, max_length=max_len, return_attention_mask=True, return_tensors='pt') | |
| inputs={"input_ids": tokenized_inputs['input_ids'], | |
| "attention_mask": tokenized_inputs['attention_mask']} | |
| return inputs | |
| def generate_answers(text): | |
| inputs = tokenize_data(text) | |
| print inputs | |
| results= model.predict(inputs) | |
| answer = tokenizer.decode(results[0], skip_special_tokens=True) | |
| return answer | |
| iface = gr.Interface(fn=generate_answers, inputs=['text'], outputs=["text"]) | |
| iface.launch(inline=False, share=True) |