eaglelandsonce commited on
Commit
9a869c1
·
verified ·
1 Parent(s): 254fba7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py CHANGED
@@ -1,3 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
3
  from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
@@ -60,3 +128,4 @@ if st.sidebar.button("Generate Image"):
60
  # Display instructions
61
  st.sidebar.info("Enter a prompt and click 'Generate Image' to create a new image.")
62
 
 
 
1
+ import streamlit as st
2
+ from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
3
+ from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
4
+ from clarifai_grpc.grpc.api.status import status_code_pb2
5
+ from PIL import Image
6
+ from io import BytesIO
7
+ from base64 import b64decode
8
+
9
+ # Streamlit page configuration
10
+ st.set_page_config(page_title='DALL-E Image Generator', layout='wide')
11
+
12
+ # Streamlit sidebar elements
13
+ st.sidebar.title("DALL-E Image Generator")
14
+ prompt = st.sidebar.text_input("Enter your prompt:", value='A penguin watching the sunset.')
15
+ PAT = st.sidebar.text_input("Enter your Personal Access Token:", type="password")
16
+
17
+ # Constants
18
+ USER_ID = 'openai'
19
+ APP_ID = 'dall-e'
20
+ MODEL_ID = 'dall-e-3'
21
+ MODEL_VERSION_ID = 'dc9dcb6ee67543cebc0b9a025861b868'
22
+
23
+ # Streamlit main page
24
+ st.title('Generate Images with DALL-E and Clarifai')
25
+ if st.sidebar.button("Generate Image"):
26
+ if PAT: # Check if PAT is filled
27
+ with st.spinner('Generating Image...'):
28
+ # Clarifai gRPC setup
29
+ channel = ClarifaiChannel.get_grpc_channel()
30
+ stub = service_pb2_grpc.V2Stub(channel)
31
+ metadata = (('authorization', 'Key ' + PAT),)
32
+ userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
33
+
34
+ post_model_outputs_response = stub.PostModelOutputs(
35
+ service_pb2.PostModelOutputsRequest(
36
+ user_app_id=userDataObject,
37
+ model_id=MODEL_ID,
38
+ version_id=MODEL_VERSION_ID,
39
+ inputs=[
40
+ resources_pb2.Input(
41
+ data=resources_pb2.Data(
42
+ text=resources_pb2.Text(raw=prompt)
43
+ )
44
+ )
45
+ ]
46
+ ),
47
+ metadata=metadata
48
+ )
49
+
50
+ if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
51
+ st.error("Error in generating image: " + post_model_outputs_response.status.description)
52
+ else:
53
+ # Decode the base64 image and display
54
+ output = post_model_outputs_response.outputs[0].data.image.base64
55
+ image = Image.open(BytesIO(b64decode(output)))
56
+ st.image(image, caption='Generated Image', use_column_width
57
+
58
+ else:
59
+ st.sidebar.warning("Please enter your Personal Access Token.")
60
+
61
+
62
+
63
+
64
+
65
+
66
+ '''
67
+
68
+
69
  import streamlit as st
70
  from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
71
  from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
 
128
  # Display instructions
129
  st.sidebar.info("Enter a prompt and click 'Generate Image' to create a new image.")
130
 
131
+ '''