|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
from peft import PeftModel |
|
|
|
|
|
base_model_name = "meta-llama/Llama-3-8B" |
|
|
|
|
|
lora_model_name = "starnernj/Early-Christian-Church-Fathers-LLaMA-3.1-Fine-Tuned" |
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained(base_model_name) |
|
|
|
|
|
model = PeftModel.from_pretrained(model, lora_model_name) |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(base_model_name) |
|
|
|
|
|
def chatbot_response(user_input): |
|
inputs = tokenizer(user_input, return_tensors="pt") |
|
outputs = model.generate(**inputs, max_length=400) |
|
return tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=chatbot_response, |
|
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."), |
|
outputs="text", |
|
title="Early Christian Church Fathers Fine-Tuned LLaMA 3.1 8B with LoRA", |
|
description="A chatbot using my fine-tuned LoRA adapter on LLaMA 3.1 8B, tuned on thousands of writings of the early Christian Church Fathers.", |
|
) |
|
|
|
interface.launch() |