8B-on-GPU-ZERO / app.py
alex-abb's picture
Update app.py
e9031f8 verified
raw
history blame
772 Bytes
import gradio as gr
import spaces
## Load model directly
# Load model directly
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-72B-Instruct")
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2-72B-Instruct")
@spaces.GPU(duration=120)
# Fonction de génération de texte
def generate_text(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
response_ids = model.generate(inputs.input_ids)
response_text = tokenizer.decode(response_ids[0], skip_special_tokens=True)
return response_text
# Définir une fonction pour l'interface de chat
def chatbot(message,history):
return generate_text(message)
gr.ChatInterface(chatbot).launch()