Spaces:
Running
Running
File size: 2,448 Bytes
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 |
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="🖼️")
st.markdown("<style>body { background-color: #1E1E1E; color: #FFFFFF; }</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_column_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": "llava-hf/llava-1.5-7b-hf",
"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": 0
}
# 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("Prompt copied to clipboard!")
st.write(generated_prompt)
else:
st.error(f"Failed to generate prompt: {response.status_code} - {response.text}")
|