Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
base_model_name = "abhinand/tamil-llama-7b-instruct-v0.1"
|
| 7 |
-
|
| 8 |
|
| 9 |
-
# Load
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
| 11 |
tokenizer.pad_token = tokenizer.eos_token
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
device_map="auto",
|
| 17 |
-
|
| 18 |
)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
def generate_response(instruction, temperature=0.7, max_length=512):
|
| 21 |
# Format the input text
|
| 22 |
input_text = f"### Instruction: {instruction}\n\n### Response:"
|
|
@@ -57,10 +70,7 @@ demo = gr.Interface(
|
|
| 57 |
],
|
| 58 |
outputs=gr.Textbox(label="பதில்"),
|
| 59 |
title="Tamil LLaMA - ஆதியாகமம் விளக்க உதவி",
|
| 60 |
-
description=""
|
| 61 |
-
ஆதியாகமம் முதல் அதிகாரம் பற்றிய கேள்விகளுக்கு விளக்கம் அளிக்கும் AI மாதிரி.
|
| 62 |
-
Base Model: abhinand/tamil-llama-7b-instruct-v0.1
|
| 63 |
-
""",
|
| 64 |
examples=example_prompts,
|
| 65 |
allow_flagging="never",
|
| 66 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 3 |
+
from peft import PeftModel, PeftConfig
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
# Base model and adapter paths
|
| 7 |
base_model_name = "abhinand/tamil-llama-7b-instruct-v0.1"
|
| 8 |
+
adapter_name = "joelelangovan/tamil-llama-genesis-finetuned"
|
| 9 |
|
| 10 |
+
# Load base tokenizer
|
| 11 |
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
| 12 |
tokenizer.pad_token = tokenizer.eos_token
|
| 13 |
|
| 14 |
+
# Setup quantization
|
| 15 |
+
bnb_config = BitsAndBytesConfig(
|
| 16 |
+
load_in_4bit=True,
|
| 17 |
+
bnb_4bit_quant_type="nf4",
|
| 18 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 19 |
+
bnb_4bit_use_double_quant=False
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Load base model
|
| 23 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 24 |
+
base_model_name,
|
| 25 |
+
quantization_config=bnb_config,
|
| 26 |
device_map="auto",
|
| 27 |
+
trust_remote_code=True
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# Load and apply LoRA adapter
|
| 31 |
+
model = PeftModel.from_pretrained(base_model, adapter_name)
|
| 32 |
+
|
| 33 |
def generate_response(instruction, temperature=0.7, max_length=512):
|
| 34 |
# Format the input text
|
| 35 |
input_text = f"### Instruction: {instruction}\n\n### Response:"
|
|
|
|
| 70 |
],
|
| 71 |
outputs=gr.Textbox(label="பதில்"),
|
| 72 |
title="Tamil LLaMA - ஆதியாகமம் விளக்க உதவி",
|
| 73 |
+
description="ஆதியாகமம் முதல் அதிகாரம் பற்றிய கேள்விகளுக்கு விளக்கம் அளிக்கும் AI மாதிரி",
|
|
|
|
|
|
|
|
|
|
| 74 |
examples=example_prompts,
|
| 75 |
allow_flagging="never",
|
| 76 |
)
|