Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
3 |
+
from textwrap import fill
|
4 |
+
|
5 |
+
# Load fine-tuned model and tokenizer
|
6 |
+
last_checkpoint = "Jyotiyadav/InsuranceModel1.0"
|
7 |
+
finetuned_model = T5ForConditionalGeneration.from_pretrained(last_checkpoint)
|
8 |
+
tokenizer = T5Tokenizer.from_pretrained(last_checkpoint)
|
9 |
+
|
10 |
+
# Define inference function
|
11 |
+
def answer_question(question):
|
12 |
+
# Format input
|
13 |
+
inputs = ["Please answer this question: " + question]
|
14 |
+
inputs = tokenizer(inputs, return_tensors="pt")
|
15 |
+
|
16 |
+
# Generate answer
|
17 |
+
outputs = finetuned_model.generate(**inputs)
|
18 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
|
20 |
+
# Wrap answer for better display
|
21 |
+
return fill(answer, width=80)
|
22 |
+
|
23 |
+
# Create Gradio interface
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=answer_question,
|
26 |
+
inputs="text",
|
27 |
+
outputs="text",
|
28 |
+
title="Question Answering with T5 Model",
|
29 |
+
description="Enter your question to get the answer.",
|
30 |
+
examples=[
|
31 |
+
["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?"],
|
32 |
+
["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?"],
|
33 |
+
["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?"]
|
34 |
+
]
|
35 |
+
)
|
36 |
+
|
37 |
+
# Launch Gradio interface
|
38 |
+
iface.launch()
|