Spaces:
Running
Running
File size: 2,873 Bytes
7c56b7b b176c14 7c56b7b 79ec99d b500c44 79ec99d 7c56b7b 79ec99d 7c56b7b b500c44 7c56b7b c7bca57 7c56b7b 5180af7 7c56b7b b500c44 7c56b7b |
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 |
import streamlit as st
import requests
import os
import json
# Set the Nebius API key
API_KEY = os.environ.get("NEBIUS_API_KEY")
API_URL = "https://api.studio.nebius.ai/v1/chat/completions"
# Streamlit app configuration
st.set_page_config(page_title="Image to Prompt Converter", layout="centered", page_icon="🖼️")
# Apply custom styles
st.markdown(
"""
<style>
body {
background: linear-gradient(135deg, #1e3c72, #2a5298);
color: #FFFFFF;
font-family: 'Arial', sans-serif;
}
.stApp {
align-items: center;
justify-content: center;
}
img {
border-radius: 10px;
margin-bottom: 20px;
max-width: 100%;
height: auto;
}
h1, h2, h3 {
text-align: center;
}
</style>
""",
unsafe_allow_html=True
)
# App title
st.title("Image to Prompt Converter")
st.markdown("**Upload an image and generate a detailed prompt.**")
# Image upload
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
# Display the uploaded image
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
# Generate button
if st.button("Generate Prompt"):
# Prepare the API payload
files = {"file": uploaded_file.getvalue()}
headers = {"Authorization": f"Bearer {API_KEY}"}
data = {
"model": "Qwen/Qwen2-VL-7B-Instruct",
"messages": [
{
"role": "system",
"content": """You are an image to prompt converter. Your work is to observe each and every detail of the image and craft a detailed prompt under 75 words in this format: [image content/subject, description of action, state, and mood], [art form, style], [artist/photographer reference if needed], [additional settings such as camera and lens settings, lighting, colors, effects, texture, background, rendering]."""
}
],
"temperature": 1
}
# Call the Nebius API
response = requests.post(API_URL, headers=headers, data=json.dumps(data))
if response.status_code == 200:
# Extract the generated prompt
result = response.json()
generated_prompt = result.get("choices", [{}])[0].get("message", {}).get("content", "No prompt generated.")
# Display the generated prompt
st.subheader("Generated Prompt")
st.text_area("", generated_prompt, height=200)
# Copy button
if st.button("Copy Prompt"):
st.write("Copy functionality is not supported in this environment. Please manually copy the text.")
else:
st.error(f"Failed to generate prompt: {response.status_code} - {response.text}")
|