File size: 1,760 Bytes
6cf296d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7e1b0d
6cf296d
 
 
 
 
 
 
 
 
11341ee
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
39
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)