devNaam commited on
Commit
e66f1a0
Β·
verified Β·
1 Parent(s): 77914df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ model_id = "devNaam/vakilai-llama32-3b-v1"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
8
+
9
+ model = AutoModelForCausalLM.from_pretrained(
10
+ model_id,
11
+ torch_dtype=torch.float16,
12
+ device_map="auto"
13
+ )
14
+
15
+ def generate_response(prompt):
16
+
17
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
18
+
19
+ outputs = model.generate(
20
+ **inputs,
21
+ max_new_tokens=300,
22
+ temperature=0.7,
23
+ top_p=0.9
24
+ )
25
+
26
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
27
+
28
+ return response
29
+
30
+
31
+ iface = gr.Interface(
32
+ fn=generate_response,
33
+ inputs=gr.Textbox(lines=5, placeholder="Ask VakilAI a legal question..."),
34
+ outputs="text",
35
+ title="VakilAI Legal Assistant",
36
+ description="AI Legal assistant trained on Indian legal data."
37
+ )
38
+
39
+ iface.launch()