try3 app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Use
|
| 5 |
-
generator = pipeline("text-generation", model="
|
| 6 |
|
| 7 |
-
# Caption generation function
|
| 8 |
def generate_caption(user_input):
|
| 9 |
prompt = f"""You are an expert Instagram caption writer.
|
| 10 |
Given this input, craft one stylish, short, and emotionally resonant caption (max 20 words).
|
|
@@ -16,12 +15,11 @@ Caption:"""
|
|
| 16 |
response = generator(prompt, max_new_tokens=50, do_sample=True, temperature=0.8)
|
| 17 |
return response[0]['generated_text'].split("Caption:")[-1].strip()
|
| 18 |
|
| 19 |
-
# Example
|
| 20 |
-
example_prompt = """Vibe:
|
| 21 |
-
Photo: me
|
| 22 |
-
Captions I like: '
|
| 23 |
|
| 24 |
-
# Gradio interface
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=generate_caption,
|
| 27 |
inputs=gr.Textbox(
|
|
@@ -35,4 +33,4 @@ iface = gr.Interface(
|
|
| 35 |
description="Tell us your vibe and we’ll craft a personalized caption for your Instagram post or story."
|
| 36 |
)
|
| 37 |
|
| 38 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Use a public model (works without login)
|
| 5 |
+
generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
|
| 6 |
|
|
|
|
| 7 |
def generate_caption(user_input):
|
| 8 |
prompt = f"""You are an expert Instagram caption writer.
|
| 9 |
Given this input, craft one stylish, short, and emotionally resonant caption (max 20 words).
|
|
|
|
| 15 |
response = generator(prompt, max_new_tokens=50, do_sample=True, temperature=0.8)
|
| 16 |
return response[0]['generated_text'].split("Caption:")[-1].strip()
|
| 17 |
|
| 18 |
+
# Example to show in UI
|
| 19 |
+
example_prompt = """Vibe: confident and stylish
|
| 20 |
+
Photo: me stepping out of a cab in heels at night in NYC
|
| 21 |
+
Captions I like: 'main character energy', 'own the moment'"""
|
| 22 |
|
|
|
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=generate_caption,
|
| 25 |
inputs=gr.Textbox(
|
|
|
|
| 33 |
description="Tell us your vibe and we’ll craft a personalized caption for your Instagram post or story."
|
| 34 |
)
|
| 35 |
|
| 36 |
+
iface.launch()
|