Im-prmpt / app.py
mrbeliever's picture
Update app.py
7c56b7b verified
raw
history blame
2.45 kB
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}")