Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
generator = pipeline("
|
| 6 |
|
| 7 |
def generate_caption(prompt):
|
| 8 |
-
|
| 9 |
|
| 10 |
result = generator(
|
| 11 |
-
|
| 12 |
-
max_length=
|
| 13 |
-
num_return_sequences=1
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
iface = gr.Interface(
|
| 21 |
fn=generate_caption,
|
| 22 |
inputs=gr.Textbox(placeholder="Enter product (e.g. gold earrings)"),
|
| 23 |
outputs=gr.Textbox(label="Captions"),
|
| 24 |
title="✨ AI Caption Generator",
|
| 25 |
-
description="Generate
|
| 26 |
)
|
| 27 |
|
| 28 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Use a model that works with text-generation properly
|
| 5 |
+
generator = pipeline("text-generation", model="gpt2")
|
| 6 |
|
| 7 |
def generate_caption(prompt):
|
| 8 |
+
base_prompt = f"Luxury Instagram captions for {prompt}:\n1."
|
| 9 |
|
| 10 |
result = generator(
|
| 11 |
+
base_prompt,
|
| 12 |
+
max_length=70,
|
| 13 |
+
num_return_sequences=1,
|
| 14 |
+
temperature=0.7
|
| 15 |
)
|
| 16 |
|
| 17 |
+
text = result[0]["generated_text"]
|
| 18 |
|
| 19 |
+
# Clean prefix
|
| 20 |
+
text = text.replace(base_prompt, "").strip()
|
| 21 |
+
|
| 22 |
+
# Split into lines
|
| 23 |
+
lines = [line.strip() for line in text.split("\n") if line.strip()]
|
| 24 |
+
|
| 25 |
+
return "\n".join(lines[:3])
|
| 26 |
|
| 27 |
iface = gr.Interface(
|
| 28 |
fn=generate_caption,
|
| 29 |
inputs=gr.Textbox(placeholder="Enter product (e.g. gold earrings)"),
|
| 30 |
outputs=gr.Textbox(label="Captions"),
|
| 31 |
title="✨ AI Caption Generator",
|
| 32 |
+
description="Generate simple captions"
|
| 33 |
)
|
| 34 |
|
| 35 |
iface.launch()
|