AmiyendraOP's picture
Update app.py
60b634d verified
raw
history blame
886 Bytes
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import torch
import gradio as gr
model_id = "AmiyendraOP/llama3-legal-finetuned"
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
# Set device properly
device = 0 if torch.cuda.is_available() else -1
# Use pipeline for text generation
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
# Define chat function
def chat(prompt):
response = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7)[0]["generated_text"]
return response
# Launch Gradio app
gr.Interface(
fn=chat,
inputs=gr.Textbox(lines=4, placeholder="Enter legal question...", label="Your Question"),
outputs=gr.Textbox(label="Response"),
title="LLaMA 3 Legal Chatbot (Fine-tuned)",
).launch()