Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,18 @@
|
|
1 |
import streamlit as st
|
2 |
-
from clarifai.
|
3 |
-
import base64
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
|
|
6 |
|
|
|
7 |
PAT = '96eccae9a5944c1097477f0529306410'
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Streamlit page configuration
|
10 |
st.title('Image Generation with Clarifai')
|
11 |
st.write('Enter a prompt and generate an image.')
|
@@ -15,11 +22,11 @@ user_input = st.text_input('Enter your image prompt')
|
|
15 |
|
16 |
# Process the input when a prompt is given
|
17 |
if user_input:
|
18 |
-
#
|
19 |
-
|
20 |
-
model_prediction = Model("https://clarifai.com/stability-ai/stable-diffusion-2/models/stable-diffusion-xl").predict_by_bytes(user_input.encode(), input_type="text", inference_params=inference_params)
|
21 |
|
22 |
-
|
|
|
23 |
|
24 |
# Convert base64 to PIL Image
|
25 |
image_data = base64.b64decode(output_base64)
|
@@ -29,4 +36,4 @@ if user_input:
|
|
29 |
st.image(image, caption='Generated Image', use_column_width=True)
|
30 |
|
31 |
# Optional: Print additional image info
|
32 |
-
st.write(model_prediction
|
|
|
1 |
import streamlit as st
|
2 |
+
from clarifai.rest import ClarifaiApp
|
|
|
3 |
from PIL import Image
|
4 |
from io import BytesIO
|
5 |
+
import base64
|
6 |
|
7 |
+
# Your Personal Access Token
|
8 |
PAT = '96eccae9a5944c1097477f0529306410'
|
9 |
|
10 |
+
# Initialize Clarifai app
|
11 |
+
app = ClarifaiApp(api_key=PAT)
|
12 |
+
|
13 |
+
# Specify the model ID (replace 'YOUR_MODEL_ID' with the actual model ID)
|
14 |
+
model = app.models.get('YOUR_MODEL_ID')
|
15 |
+
|
16 |
# Streamlit page configuration
|
17 |
st.title('Image Generation with Clarifai')
|
18 |
st.write('Enter a prompt and generate an image.')
|
|
|
22 |
|
23 |
# Process the input when a prompt is given
|
24 |
if user_input:
|
25 |
+
# Get model prediction
|
26 |
+
model_prediction = model.predict_by_bytes(user_input.encode(), input_type="text")
|
|
|
27 |
|
28 |
+
# Extract the image data
|
29 |
+
output_base64 = model_prediction['outputs'][0]['data']['image']['base64']
|
30 |
|
31 |
# Convert base64 to PIL Image
|
32 |
image_data = base64.b64decode(output_base64)
|
|
|
36 |
st.image(image, caption='Generated Image', use_column_width=True)
|
37 |
|
38 |
# Optional: Print additional image info
|
39 |
+
st.write(model_prediction['outputs'][0]['data']['image']['image_info'])
|