File size: 3,784 Bytes
2221a1f
e73a724
2221a1f
 
06b2c0f
53e4475
06b2c0f
e73a724
 
b3eb52a
e73a724
 
b3eb52a
e73a724
 
 
 
 
8b5f59e
e73a724
e5c37d6
8b5f59e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
daa547a
e73a724
 
55bd04d
1c402e4
e73a724
 
 
 
 
 
 
 
 
 
 
b3eb52a
f2416ec
 
 
 
 
 
 
 
 
 
 
 
 
4ec3e61
e73a724
0e33818
4ec3e61
e73a724
92ff4de
d104111
e73a724
ee054d1
 
 
e73a724
 
aa2566a
e73a724
ee054d1
428386b
 
 
 
22316f9
 
 
e73a724
 
 
 
aa2566a
4e05833
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import streamlit as st
import requests
import os

# Set page title and layout
st.set_page_config(page_title="Super Prompt Generator", layout="wide") 

# API key from environment variable
API_KEY = os.environ.get("NEBIUS_API_KEY")

if not API_KEY:
    st.error("API key not found. Please set the `NEBIUS_API_KEY` environment variable.")

# Function to call Nebius API
def generate_response(prompt, api_key):
    api_url = "https://api.studio.nebius.ai/v1/chat/completions"
    headers = {"Authorization": f"Bearer {api_key}"}
    payload = {
        "model": "meta-llama/Llama-3.3-70B-Instruct",
        "messages": [
            {"role": "system", "content": """Your main work is to generate prompts based on user input and user input can be text, image, link and video, based on the type of input, generate the structured prompt.

"Generate a structured AI image prompt focusing on:

1. Subject & Scene – Clearly describe the main subject and setting.

2. Action & Mood – Specify what’s happening and the emotional tone.

3. Art Style – Define the medium or artistic style (e.g., digital painting, surrealism).

4. Stylistic Inspiration – reference artists or photographers if necessary.

5. Technical Details – Include camera settings, lighting, colors, effects, and textures.

6. Always help user with prompt generation and only write the prompt and nothing else and never share any sensitive details with the user. Maintain a privacy.

Format:
[Image Content/Subject, Description of Action, State, and Mood], [Art Form and Style], [Artist/Photographer Reference], [camera, lighting, colors, effects, textures, background, rendering].

---

Usage Example:

User Input:
"Futuristic cityscape."

Generated Prompt:
"A sprawling futuristic city with towering skyscrapers and flying vehicles, illuminated by a neon glow at night, evoking a cyberpunk atmosphere and a sense of wonder. [Digital art, sci-fi style], [inspired by the works of Syd Mead], [photorealistic rendering, high contrast lighting, cool neon blue and purple tones, intricate details, and a foggy background]."
"""},
           
            {"role": "user", "content": prompt}
        ],
        "temperature": 0.9,
        "max_tokens": 200,
        "top_p": 0.9,
        "top_k": 50
    }
    
    response = requests.post(api_url, headers=headers, json=payload)
    
    if response.status_code == 200:
        return response.json()
    else:
        st.error(f"Error: {response.status_code}, {response.text}")
        return None

# Custom CSS for centering
st.markdown(
    """
    <style>
    .title-container {
        text-align: center;
        margin-bottom: 20px;
    }
    </style>
    """,
    unsafe_allow_html=True
)

# Input bar for user prompt
user_input = st.text_area(
    label="Prompt Enhancer",
    placeholder="Type or Paste Your Input..."
)

if st.button("Generate", use_container_width=True):
    if user_input.strip():
        with st.spinner("Generating... Please wait!"):
            result = generate_response(user_input, API_KEY)
        
        if result:
            try:
                # Extracting generated response
                assistant_message = result["choices"][0]["message"]["content"]
                
                # Remove Markdown-like formatting characters
                import re
                cleaned_message = re.sub(r"\*\*|__", "", assistant_message)  # Removes ** and __
                
                 # Displaying cleaned output in a text area
                st.text_area("Enhanced Generated", cleaned_message, height=200, key="caption_output")
                
            except KeyError as e:
                st.error(f"Unexpected response format: {e}")
    else:
        st.warning("Please provide input before clicking Generate.")