devNaam commited on
Commit
090538e
·
1 Parent(s): c1731e2

Add VakilAI model

Browse files
Files changed (1) hide show
  1. app.py +36 -6
app.py CHANGED
@@ -1,14 +1,44 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!! Welcome to AI Vakil"
5
 
6
  demo = gr.Interface(
7
- fn=greet,
8
- inputs="text",
9
  outputs="text",
10
- title="AI Vakil",
11
- description="First test deployment"
12
  )
13
 
14
  demo.launch()
 
1
  import gradio as gr
2
+ import torch
3
+
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+ from peft import PeftModel
6
+
7
+ BASE_MODEL = "meta-llama/Llama-3.2-3B"
8
+ ADAPTER_MODEL = "devNaam/vakilai-llama32-3b-v1"
9
+
10
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
11
+
12
+ model = AutoModelForCausalLM.from_pretrained(
13
+ BASE_MODEL,
14
+ torch_dtype=torch.float16,
15
+ device_map="auto"
16
+ )
17
+
18
+ model = PeftModel.from_pretrained(model, ADAPTER_MODEL)
19
+
20
+ def vakil_ai(prompt):
21
+
22
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
23
+
24
+ output = model.generate(
25
+ **inputs,
26
+ max_new_tokens=300,
27
+ temperature=0.7,
28
+ top_p=0.9
29
+ )
30
+
31
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
32
+
33
+ return response
34
 
 
 
35
 
36
  demo = gr.Interface(
37
+ fn=vakil_ai,
38
+ inputs=gr.Textbox(lines=4, placeholder="Ask your legal question..."),
39
  outputs="text",
40
+ title="AI Vakil – Legal Assistant",
41
+ description="VakilAI powered by Llama 3.2"
42
  )
43
 
44
  demo.launch()