import gradio as gr from transformers import T5ForConditionalGeneration, T5Tokenizer from textwrap import fill # Load fine-tuned model and tokenizer last_checkpoint = "Jyotiyadav/InsuranceModel1.0" finetuned_model = T5ForConditionalGeneration.from_pretrained(last_checkpoint) tokenizer = T5Tokenizer.from_pretrained(last_checkpoint) # Define inference function def answer_question(question): # Format input inputs = ["Please answer this question: " + question] inputs = tokenizer(inputs, return_tensors="pt") # Generate answer outputs = finetuned_model.generate(**inputs) answer = tokenizer.decode(outputs[0], skip_special_tokens=True) # Wrap answer for better display return fill(answer, width=80) # Create Gradio interface iface = gr.Interface( fn=answer_question, inputs="text", outputs="text", title="Insurance Claim Prediction Using T5 Model", description="Enter your question to get the answer.", examples=[ ["For a Male customer with an annual income of $850000, who bought a Pale White Mitsubishi Diamante (Overhead Camshaft engine) from Classic Chevy in Riga on 2022-Jan-2, priced at $12000, what was the claim amount?"], ["For a Male customer with an annual income of $13500, who bought a Pale White Chrysler Sebring Coupe (Overhead Camshaft engine) from Suburban Ford in Ventspils on 2022-Jan-3, priced at $26000, what was the claim amount?"], ["For a Male customer with an annual income of $13500, who bought a Black Lexus LS400 (Double\u00c3\u201a\u00c2\u00a0Overhead Camshaft engine) from Saab-Belle Dodge in Liepaja on 2022-Jan-12, priced at $39000, what was the claim amount?"] ] ) # Launch Gradio interface iface.launch(inline=True, debug=True)