Spaces:
Runtime error
Runtime error
| from transformers import AutoModelForSeq2SeqLM, AutoTokenizer | |
| from fastapi import FastAPI | |
| import gradio as gr | |
| # Load model and tokenizer | |
| model_name = "Vamsi/T5_Paraphrase_Paws" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
| # Paraphrasing function | |
| def paraphrase(text): | |
| input_text = "paraphrase: " + text + " </s>" | |
| inputs = tokenizer([input_text], return_tensors="pt", padding=True) | |
| outputs = model.generate(**inputs, max_length=100, num_beams=5, num_return_sequences=1) | |
| return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| # Create Gradio interface | |
| interface = gr.Interface(fn=paraphrase, inputs="text", outputs="text") | |
| # Mount Gradio to FastAPI for API calls | |
| app = FastAPI() | |
| app = gr.mount_gradio_app(app, interface, path="/") # now POST to / is accepted | |