Spaces:
Runtime error
Runtime error
File size: 2,612 Bytes
8e27d5b 8ff118b 5e6b78a 8ff118b 5e6b78a 8ff118b 8e27d5b 8ff118b 8e27d5b 8ff118b 8e27d5b 8ff118b 5e6b78a 8ff118b 8e27d5b 8ff118b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Use base model's tokenizer
base_model_name = "abhinand/tamil-llama-7b-instruct-v0.1"
model_name = "joelelangovan/tamil-llama-genesis-finetuned"
# Load tokenizer from base model
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
tokenizer.pad_token = tokenizer.eos_token
# Load fine-tuned model
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
torch_dtype=torch.float16,
)
def generate_response(instruction, temperature=0.7, max_length=512):
# Format the input text
input_text = f"### Instruction: {instruction}\n\n### Response:"
# Tokenize
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
# Generate
outputs = model.generate(
**inputs,
max_length=max_length,
num_return_sequences=1,
temperature=temperature,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
# Decode and return response
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Remove the instruction part from response
response = response.split("### Response:")[-1].strip()
return response
# Example prompts
example_prompts = [
["ஆதியாகமம் 1:1 வசனத்தின் பொருளை விளக்குங்கள்"],
["ஆதியாகமம் 1:2 வசனத்தை தமிழில் விவரிக்கவும்"],
["ஆதியாகமம் 1:3 வசனத்தின் முக்கிய கருத்து என்ன?"]
]
# Create Gradio interface
demo = gr.Interface(
fn=generate_response,
inputs=[
gr.Textbox(label="கேள்வி / வினா", placeholder="உங்கள் கேள்வியை இங்கே உள்ளிடவும்..."),
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Temperature"),
gr.Slider(minimum=64, maximum=1024, value=512, step=64, label="Max Length"),
],
outputs=gr.Textbox(label="பதில்"),
title="Tamil LLaMA - ஆதியாகமம் விளக்க உதவி",
description="""
ஆதியாகமம் முதல் அதிகாரம் பற்றிய கேள்விகளுக்கு விளக்கம் அளிக்கும் AI மாதிரி.
Base Model: abhinand/tamil-llama-7b-instruct-v0.1
""",
examples=example_prompts,
allow_flagging="never",
)
# Launch the demo
demo.launch() |