Multiverse26 commited on
Commit
d7390e2
·
verified ·
1 Parent(s): fd493a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -1,28 +1,35 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Better instruction-following small model
5
- generator = pipeline("text2text-generation", model="google/flan-t5-small")
6
 
7
  def generate_caption(prompt):
8
- text = f"Write 3 short, elegant luxury Instagram captions for: {prompt}. Each caption on a new line."
9
 
10
  result = generator(
11
- text,
12
- max_length=100,
13
- num_return_sequences=1
 
14
  )
15
 
16
- output = result[0]["generated_text"]
17
 
18
- return output.strip()
 
 
 
 
 
 
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 clean luxury captions"
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()