musaashaikh commited on
Commit
04b414a
·
verified ·
1 Parent(s): fb65314

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import torch
5
+
6
+ # Load GPT-2 model and tokenizer
7
+ model = AutoModelForCausalLM.from_pretrained("gpt2")
8
+ tokenizer = AutoTokenizer.from_pretrained("gpt2")
9
+
10
+ def compare_claims(claim1, claim2):
11
+ """
12
+ Compare two insurance claims using GPT-2.
13
+ """
14
+ prompt = f"Compare these two health insurance claims:\n\nClaim 1: {claim1}\n\nClaim 2: {claim2}\n\nDifferences and similarities:"
15
+
16
+ # Tokenize input
17
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
18
+
19
+ # Generate response
20
+ gen_tokens = model.generate(
21
+ input_ids,
22
+ do_sample=True,
23
+ temperature=0.7, # Adjust creativity
24
+ max_length=150, # Limit output size
25
+ pad_token_id=tokenizer.eos_token_id
26
+ )
27
+
28
+ # Decode and return output
29
+ return tokenizer.decode(gen_tokens[0], skip_special_tokens=True)
30
+
31
+ def main():
32
+ """
33
+ Launch the Gradio interface for claim comparison.
34
+ """
35
+ # Define the Gradio interface
36
+ interface = gr.Interface(
37
+ fn=compare_claims,
38
+ inputs=[
39
+ gr.Textbox(label="claim1", placeholder="Enter first claim description..."),
40
+ gr.Textbox(label="claim2", placeholder="Enter second claim description...")
41
+ ],
42
+ outputs="text",
43
+ title="Claims Comparison",
44
+ description="Enter two claims to compare their differences."
45
+ )
46
+
47
+ # Launch the Gradio app
48
+ interface.launch()
49
+
50
+ if __name__ == "__main__":
51
+ main()