YUVALON commited on
Commit
15c931a
·
verified ·
1 Parent(s): a7cabb5

try1 app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a small language model for text generation (works on CPU)
5
+ generator = pipeline("text-generation", model="EleutherAI/gpt-neo-125M")
6
+
7
+ # Prompt engineering function
8
+ def generate_caption(user_input):
9
+ prompt = f"""You are an expert Instagram caption writer.
10
+ Create a stylish and catchy caption based on the following input:
11
+ {user_input}
12
+ Caption:"""
13
+ response = generator(prompt, max_length=40, do_sample=True, temperature=0.9)
14
+ return response[0]['generated_text'].split("Caption:")[-1].strip()
15
+
16
+ # Gradio interface
17
+ iface = gr.Interface(
18
+ fn=generate_caption,
19
+ inputs=gr.Textbox(label="Describe the photo, vibe, and example captions you like", lines=5, placeholder="e.g., Vibe: chill, Photo: girl by the beach, Captions I like: 'based on a true story'"),
20
+ outputs=gr.Textbox(label="Generated Instagram Caption"),
21
+ title="📸 Caption Crafter",
22
+ description="Tell us your vibe and we'll craft a personalized caption for your Instagram post or story."
23
+ )
24
+
25
+ iface.launch()