3d-prompt / app.py
Miguelpef's picture
Upload app.py
ed900af verified
raw
history blame
1.32 kB
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from peft import PeftModel, PeftConfig
import gradio as gr
# Define the repository ID
repo_id = "Miguelpef/bart-base-lora-3DPrompt" # Replace with your repository name
# Load the PEFT configuration from the Hub
peft_config = PeftConfig.from_pretrained(repo_id)
# Load the base model from the Hub
model = AutoModelForSeq2SeqLM.from_pretrained(peft_config.base_model_name_or_path)
# Load the tokenizer from the Hub
tokenizer = AutoTokenizer.from_pretrained(repo_id)
# Wrap the base model with PEFT
model = PeftModel.from_pretrained(model, repo_id)
# Now you can use the model for inference as before
def generar_prompt_desde_objeto(objeto):
prompt = objeto
inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
outputs = model.generate(**inputs, max_length=100)
prompt_generado = tokenizer.decode(outputs[0], skip_special_tokens=True)
return prompt_generado
# Define the Gradio interface
iface = gr.Interface(
fn=generar_prompt_desde_objeto,
inputs=gr.Textbox(lines=2, placeholder="Enter object description here..."),
outputs="text",
title="3D Prompt Generator",
description="Generates 3D prompts from object descriptions using a fine-tuned BART model.",
)
# Launch the interface
iface.launch()