|
import os |
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
import gradio as gr |
|
|
|
|
|
model_name = "bartowski/Llama-3.2-3B-Instruct-uncensored-GGUF" |
|
hf_token = os.getenv("HF_TOKEN") |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token) |
|
model = AutoModelForCausalLM.from_pretrained( |
|
model_name, |
|
use_auth_token=hf_token, |
|
device_map=None, |
|
torch_dtype="float32" |
|
) |
|
|
|
|
|
def generate_response(prompt): |
|
inputs = tokenizer(prompt, return_tensors="pt", truncation=True) |
|
outputs = model.generate(inputs["input_ids"], max_length=200, num_beams=5, early_stopping=True) |
|
return tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_response, |
|
inputs="text", |
|
outputs="text", |
|
title="LLaMA 3.2 3B Instruct Uncensored", |
|
description="Gib einen Text ein, und das Modell generiert eine Antwort basierend auf LLaMA 3.2 3B Instruct Uncensored." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|