Views
No views yet
1from unsloth import FastLanguageModel
2import torch
3
4# Load the model
5model, tokenizer = FastLanguageModel.from_pretrained(
6 model_name="saakshigupta/deepfake-explainer-llama32",
7 max_seq_length=2048,
8 load_in_4bit=True,
9)
10
11# Enable for inference
12FastLanguageModel.for_inference(model)
13
14# Example prompt
15prompt = """Analyze this deepfake detection result and provide both a technical expert explanation and a simple non-technical explanation.
16
17Below is a deepfake detection result with explanation metrics. Provide both a technical and accessible explanation of why this image is classified as it is.
18### Detection Results:
19Verdict: Deepfake
20Confidence: 0.87
21### Analysis Metrics:
22High Activation Regions: lips, nose
23Medium Activation Regions: eyes, chin
24Low Activation Regions: forehead, background
25Frequency Analysis Score: 0.79
26### Image Description:
27A man with glasses and short hair looking directly at the camera.
28### Heatmap Description:
29The heatmap shows intense red coloration around the lips and nose area, suggesting these regions contributed most to the detection verdict."""
30
31# Format for chat
32messages = [
33 {"role": "user", "content": prompt},
34]
35
36# Apply chat template
37inputs = tokenizer.apply_chat_template(
38 messages,
39 tokenize=True,
40 add_generation_prompt=True,
41 return_tensors="pt",
42).to("cuda" if torch.cuda.is_available() else "cpu")
43
44# Generate response
45from transformers import TextStreamer
46text_streamer = TextStreamer(tokenizer, skip_prompt=True)
47_ = model.generate(
48 input_ids=inputs,
49 streamer=text_streamer,
50 max_new_tokens=800,
51 use_cache=True,
52 temperature=0.7,
53 do_sample=True
54)