Lordgpt / LordgpT
Zerx966's picture
Create LordgpT
c82c46b verified
raw
history blame
1.24 kB
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the model and tokenizer
model_name = "aifeifei798/DarkIdol-Llama-3.1-8B-Instruct-1.2-Uncensored"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, load_in_8bit=True)
def generate_text(prompt, max_length=100, temperature=0.7):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
inputs["input_ids"],
max_length=max_length,
temperature=temperature,
do_sample=True,
top_p=0.9,
top_k=50,
num_return_sequences=1,
pad_token_id=tokenizer.eos_token_id,
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Create a Gradio interface
gr.Interface(
fn=generate_text,
inputs=[
gr.inputs.Textbox(label="Input Text"),
gr.inputs.Slider(label="Max Length", minimum=1, maximum=500, value=100, step=1),
gr.inputs.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.7, step=0.1),
],
outputs=gr.outputs.Textbox(label="Generated Text"),
title="LLAMA 3.1 8B Model",
description="Generate text using the LLAMA 3.1 8B model.",
).launch()