|
import gradio as gr |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
|
|
model_name = "nvidia/NVLM-D-72B" |
|
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True) |
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) |
|
|
|
|
|
def generate_text(prompt): |
|
inputs = tokenizer(prompt, return_tensors="pt") |
|
outputs = model.generate(**inputs, max_length=100) |
|
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
return generated_text |
|
|
|
|
|
interface = gr.Interface(fn=generate_text, |
|
inputs="text", |
|
outputs="text", |
|
title="NVLM-D Text Generation", |
|
description="Entrez un prompt pour générer du texte avec le modèle NVLM-D-72B.") |
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|