AmiyendraOP commited on
Commit
51202ff
Β·
verified Β·
1 Parent(s): 1aa692c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -1,20 +1,20 @@
1
- from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
- import torch
3
  import gradio as gr
 
4
 
5
  model_id = "AmiyendraOP/llama3-legal-finetuned"
6
 
7
- # Load tokenizer and model
8
  tokenizer = AutoTokenizer.from_pretrained(model_id)
9
- model = AutoModelForCausalLM.from_pretrained(model_id)
10
 
11
- # Set device properly
12
  device = 0 if torch.cuda.is_available() else -1
13
 
14
- # Use pipeline for text generation
15
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
16
 
17
- # Define chat function
18
  def chat(prompt):
19
  response = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7)[0]["generated_text"]
20
  return response
@@ -24,5 +24,5 @@ gr.Interface(
24
  fn=chat,
25
  inputs=gr.Textbox(lines=4, placeholder="Enter legal question...", label="Your Question"),
26
  outputs=gr.Textbox(label="Response"),
27
- title="LLaMA 3 Legal Chatbot (Fine-tuned)",
28
  ).launch()
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
 
2
  import gradio as gr
3
+ import torch
4
 
5
  model_id = "AmiyendraOP/llama3-legal-finetuned"
6
 
7
+ # Load tokenizer and model without quantization or bitsandbytes
8
  tokenizer = AutoTokenizer.from_pretrained(model_id)
9
+ model = AutoModelForCausalLM.from_pretrained(model_id, low_cpu_mem_usage=True, torch_dtype=torch.float32)
10
 
11
+ # Set device
12
  device = 0 if torch.cuda.is_available() else -1
13
 
14
+ # Use the text-generation pipeline
15
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
16
 
17
+ # Define a chat function
18
  def chat(prompt):
19
  response = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7)[0]["generated_text"]
20
  return response
 
24
  fn=chat,
25
  inputs=gr.Textbox(lines=4, placeholder="Enter legal question...", label="Your Question"),
26
  outputs=gr.Textbox(label="Response"),
27
+ title="LLaMA 3 Legal Chatbot (Fine-tuned)"
28
  ).launch()