Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
+
from peft import PeftModel, PeftConfig
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Define the repository ID
|
6 |
+
repo_id = "Miguelpef/bart-base-lora-3DPrompt" # Replace with your repository name
|
7 |
+
|
8 |
+
# Load the PEFT configuration from the Hub
|
9 |
+
peft_config = PeftConfig.from_pretrained(repo_id)
|
10 |
+
|
11 |
+
# Load the base model from the Hub
|
12 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(peft_config.base_model_name_or_path)
|
13 |
+
|
14 |
+
# Load the tokenizer from the Hub
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id)
|
16 |
+
|
17 |
+
# Wrap the base model with PEFT
|
18 |
+
model = PeftModel.from_pretrained(model, repo_id)
|
19 |
+
|
20 |
+
# Now you can use the model for inference as before
|
21 |
+
def generar_prompt_desde_objeto(objeto):
|
22 |
+
prompt = objeto
|
23 |
+
inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
|
24 |
+
outputs = model.generate(**inputs, max_length=100)
|
25 |
+
prompt_generado = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
26 |
+
return prompt_generado
|
27 |
+
|
28 |
+
# Define the Gradio interface
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=generar_prompt_desde_objeto,
|
31 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter object description here..."),
|
32 |
+
outputs="text",
|
33 |
+
title="3D Prompt Generator",
|
34 |
+
description="Generates 3D prompts from object descriptions using a fine-tuned BART model.",
|
35 |
+
)
|
36 |
+
|
37 |
+
# Launch the interface
|
38 |
+
iface.launch()
|