sudip2003 commited on
Commit
da74c57
·
verified ·
1 Parent(s): 1665197

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import google.generativeai as genai
4
+ import os
5
+
6
+ genai.configure(api_key=os.getenv('gemini_apy_key'))
7
+
8
+
9
+
10
+ def image_captioning_generation(image):
11
+ analysis_prompt = """
12
+ You are a professional social media strategist, specializing in creating viral content for Instagram Reels. Your task is to generate a highly engaging, viral-worthy caption and relevant hashtags based on the video.
13
+
14
+ Please create a caption that:
15
+
16
+ 1. Grabs attention immediately (strong, compelling hook).
17
+ 2. Connects emotionally with the audience.
18
+ 3. Includes a call-to-action (e.g., asking users to like, comment, or share).
19
+ 4. Fits the tone and style that resonates with a broad audience (e.g., fun, inspiring, relatable, or trending).
20
+ 5. Is optimized for virality and social sharing.
21
+
22
+ Additionally, generate the most relevant and trending hashtags that can increase the reach and discoverability of the reel. Make sure these hashtags are specific to the content and fit into popular trends, ensuring the reel has a better chance of going viral.
23
+
24
+ The output should only include the caption and a list of at least 10 hashtags.
25
+
26
+ **Output Formate** :
27
+ [
28
+ Caption : Lost in the emerald embrace of the ancient forest. The sound of the cascading water, a symphony of nature's artistry.
29
+ Hashtags : #waterfall, #nature, #naturephotography, #pnwonderland, #explore, #travel, #beautifuldestinations, #instatravel, #travelphotography, #hiking
30
+ ]
31
+ """
32
+
33
+ model = genai.GenerativeModel('models/gemini-1.5-flash')
34
+ response = model.generate_content([analysis_prompt, image], stream=True)
35
+ response.resolve()
36
+
37
+ return response.text
38
+
39
+
40
+
41
+ iface = gr.Interface(
42
+ fn=image_captioning_generation,
43
+ inputs=gr.Image(type="pil", label="Upload a Video Frame or Image"),
44
+ outputs=gr.Textbox(label="Viral Caption & Hashtags"),
45
+ title="Instagram Reel Caption Generator",
46
+ description="Upload a image to generate a viral caption and trending hashtags for Instagram Reels using Gemini AI."
47
+ )
48
+
49
+
50
+
51
+ # Launch the app
52
+ if __name__ == "__main__":
53
+ iface.launch(share=True)