xsa-dev commited on
Commit
cd3e6c8
·
verified ·
1 Parent(s): 565df3c

Upload inference_example.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. inference_example.py +24 -0
inference_example.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # FinGPT Compliance Agents - Inference Example
3
+
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+ from peft import PeftModel
6
+ import torch
7
+
8
+ # Load the model
9
+ base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B-Instruct")
10
+ model = PeftModel.from_pretrained(base_model, "your-username/fingpt-compliance-agents")
11
+ tokenizer = AutoTokenizer.from_pretrained("your-username/fingpt-compliance-agents")
12
+
13
+ # Example usage
14
+ def analyze_financial_text(text):
15
+ prompt = f"Analyze this financial text: {text}"
16
+ inputs = tokenizer(prompt, return_tensors="pt")
17
+ with torch.no_grad():
18
+ outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
19
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
20
+ return response
21
+
22
+ # Test the model
23
+ result = analyze_financial_text("Company X reported strong quarterly earnings with 15% revenue growth.")
24
+ print(result)