File size: 1,688 Bytes
c4561d9
 
 
 
1af7e7d
 
c4561d9
 
 
1af7e7d
a99b223
1af7e7d
 
a99b223
 
1af7e7d
c4561d9
 
1af7e7d
 
 
c4561d9
1748e13
1af7e7d
c4561d9
1af7e7d
 
 
 
 
 
 
c4561d9
1af7e7d
 
 
 
 
c4561d9
1af7e7d
 
 
 
 
 
 
f2efccd
1af7e7d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
import os
from PIL import Image
import google.generativeai as genai

# Konfigurasi API Gemini
secret_key = os.getenv("SECRET_KEY")
genai.configure(api_key=secret_key)

# Fungsi untuk menghasilkan prompt dari gambar
def get_gemini_response(image):
    model = genai.GenerativeModel('gemini-2.0-flash')
    input = '''You are a prompt generator. You will get an image.
    Your work is to write a prompt such that an image generator model would create most identical picture
    as the image given to you'''
    response = model.generate_content([input, image])  
    return response.text

# Konfigurasi halaman
st.set_page_config(page_title="Prompt Generation from Image", layout="wide")
st.title("🖼️ Prompt Generator from Image")

# Dua kolom layout
col1, col2 = st.columns(2)

with col1:
    st.markdown("### 📤 Upload Your Image")
    uploaded_file = st.file_uploader(
        "Drag and drop or click to upload an image...",
        type=["jpg", "jpeg", "png", "webp"],
        label_visibility="collapsed"
    )

    if uploaded_file is not None:
        image = Image.open(uploaded_file)
        st.image(image, caption="Uploaded Image", use_column_width=True)
    else:
        image = None

with col2:
    st.markdown("### 🎯 Generated Prompt")
    if uploaded_file is not None:
        if st.button("✨ Generate Prompt"):
            with st.spinner("Generating prompt..."):
                prompt = get_gemini_response(image)
            st.code(prompt, language="markdown")
            st.success("Prompt generated. Use the copy button on the top-right of the code box.")
    else:
        st.info("Please upload an image to generate a prompt.")