t / app.py
Lvk3's picture
Create app.py
7165a01 verified
raw
history blame
988 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# LLaMA 3.3 8B Modell und Tokenizer laden
model_name = "meta-llama/Llama-3.3-8B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map=None, # Keine GPU-Zuweisung
torch_dtype="float32" # Float32 für CPU
)
# Funktion für die Textgenerierung
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)
# Gradio-Interface erstellen
interface = gr.Interface(
fn=generate_response,
inputs="text",
outputs="text",
title="LLaMA 3.3 8B Text Generator (CPU)",
description="Gib einen Text ein, und LLaMA 3.3 8B generiert eine Antwort."
)
# App starten
if __name__ == "__main__":
interface.launch()