File size: 1,595 Bytes
bc32b76
4b6c42c
bc32b76
b4ff959
4b6c42c
 
 
 
 
 
 
 
 
 
 
 
 
b4ff959
4b6c42c
 
 
 
 
 
 
 
e6fa3be
4b6c42c
 
 
 
 
 
 
 
 
 
 
 
 
 
e6fa3be
4b6c42c
 
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
40
41
42
43
44
import gradio as gr
from transformers import LlamaTokenizer, LlamaForCausalLM
import torch

# Load the fine-tuned model and tokenizer
try:
    tokenizer = LlamaTokenizer.from_pretrained("./fine_tuned_llama2")
    model = LlamaForCausalLM.from_pretrained("./fine_tuned_llama2")
    model.eval()
    print("Model and tokenizer loaded successfully.")
except Exception as e:
    print(f"Error loading model or tokenizer: {e}")

# Function to predict fraud based on text input
def predict(input_text):
    if not input_text:
        return "Please enter some text to analyze."
    try:
        # Tokenize input
        inputs = tokenizer(input_text, return_tensors="pt", max_length=512, padding="max_length", truncation=True)
        # Generate output
        with torch.no_grad():
            outputs = model.generate(**inputs, max_new_tokens=50)
        # Decode and return result
        result = tokenizer.decode(outputs[0], skip_special_tokens=True)
        return result
    except Exception as e:
        return f"Error during prediction: {e}"

# Create Gradio interface with text input
interface = gr.Interface(
    fn=predict,
    inputs=gr.Textbox(
        lines=2,
        placeholder="Enter text to analyze (e.g., 'Facility backdates policies. Is this fraudulent?')",
        label="Input Text"
    ),
    outputs=gr.Textbox(label="Prediction"),
    title="Fine-Tune LLaMA 2 for Healthcare Fraud Analysis",
    description="Test the fine-tuned LLaMA 2 model to detect healthcare fraud. Enter a description of a facility's behavior to analyze."
)

# Launch the interface
interface.launch()