import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer # Load the model and tokenizer model_name = "Ransss/llama3-8B-DarkIdol-2.0-Uncensored-Q8_0-GGUF" 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 8B Model", description="Generate text using the LLAMA 3 8B model.", examples=[ ["Write a poem about the sun"], ["Generate a story about a robot"], ["Create a song lyrics about love"], ], ).launch()