File size: 1,238 Bytes
c82c46b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()