Spaces:
Running
Running
mrbeliever
commited on
Commit
•
7c56b7b
1
Parent(s):
b5bfd27
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
import json
|
5 |
+
|
6 |
+
# Set the Nebius API key
|
7 |
+
API_KEY = os.environ.get("NEBIUS_API_KEY")
|
8 |
+
API_URL = "https://api.studio.nebius.ai/v1/chat/completions"
|
9 |
+
|
10 |
+
# Streamlit app configuration
|
11 |
+
st.set_page_config(page_title="Image to Prompt Converter", layout="centered", page_icon="🖼️")
|
12 |
+
st.markdown("<style>body { background-color: #1E1E1E; color: #FFFFFF; }</style>", unsafe_allow_html=True)
|
13 |
+
|
14 |
+
# App title
|
15 |
+
st.title("Image to Prompt Converter")
|
16 |
+
st.markdown("Upload an image and generate a detailed prompt.")
|
17 |
+
|
18 |
+
# Image upload
|
19 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
20 |
+
|
21 |
+
if uploaded_file is not None:
|
22 |
+
# Display the uploaded image
|
23 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
24 |
+
|
25 |
+
# Generate button
|
26 |
+
if st.button("Generate Prompt"):
|
27 |
+
# Prepare the API payload
|
28 |
+
files = {"file": uploaded_file.getvalue()}
|
29 |
+
headers = {"Authorization": f"Bearer {API_KEY}"}
|
30 |
+
data = {
|
31 |
+
"model": "llava-hf/llava-1.5-7b-hf",
|
32 |
+
"messages": [
|
33 |
+
{
|
34 |
+
"role": "system",
|
35 |
+
"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]."""
|
36 |
+
}
|
37 |
+
],
|
38 |
+
"temperature": 0
|
39 |
+
}
|
40 |
+
|
41 |
+
# Call the Nebius API
|
42 |
+
response = requests.post(API_URL, headers=headers, data=json.dumps(data))
|
43 |
+
|
44 |
+
if response.status_code == 200:
|
45 |
+
# Extract the generated prompt
|
46 |
+
result = response.json()
|
47 |
+
generated_prompt = result.get("choices", [{}])[0].get("message", {}).get("content", "No prompt generated.")
|
48 |
+
|
49 |
+
# Display the generated prompt
|
50 |
+
st.subheader("Generated Prompt")
|
51 |
+
st.text_area("", generated_prompt, height=200)
|
52 |
+
|
53 |
+
# Copy button
|
54 |
+
if st.button("Copy Prompt"):
|
55 |
+
st.write("Prompt copied to clipboard!")
|
56 |
+
st.write(generated_prompt)
|
57 |
+
else:
|
58 |
+
st.error(f"Failed to generate prompt: {response.status_code} - {response.text}")
|