Spaces:
Runtime error
Runtime error
Commit
·
e65180f
1
Parent(s):
2fb98a5
Upload app.py
Browse files
app.py
CHANGED
|
@@ -9,36 +9,43 @@ USER_ID = 'openai'
|
|
| 9 |
APP_ID = 'dall-e'
|
| 10 |
MODEL_ID = 'dall-e-3'
|
| 11 |
MODEL_VERSION_ID = 'dc9dcb6ee67543cebc0b9a025861b868'
|
| 12 |
-
RAW_TEXT = 'ocr check mistake with image base with python opencv computer vision help out to know people'
|
| 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 |
-
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
|
| 40 |
-
st.error(f"Clarifai API request failed: {post_model_outputs_response.status.description}")
|
| 41 |
-
else:
|
| 42 |
-
output = post_model_outputs_response.outputs[0].data.image.base64
|
| 43 |
-
st.image(output, caption='Generated Image', use_column_width=True)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
APP_ID = 'dall-e'
|
| 10 |
MODEL_ID = 'dall-e-3'
|
| 11 |
MODEL_VERSION_ID = 'dc9dcb6ee67543cebc0b9a025861b868'
|
|
|
|
| 12 |
|
| 13 |
+
# Streamlit app
|
| 14 |
+
st.title("Pyresearch Image Generator")
|
| 15 |
|
| 16 |
+
# Input text prompt from the user
|
| 17 |
+
raw_text = st.text_input("Enter a text prompt:", 'ocr check mistake with image base with python opencv computer vision help out to know people')
|
| 18 |
|
| 19 |
+
# Button to generate image
|
| 20 |
+
if st.button("Generate Image"):
|
| 21 |
+
# Connect to Clarifai API
|
| 22 |
+
channel = ClarifaiChannel.get_grpc_channel()
|
| 23 |
+
stub = service_pb2_grpc.V2Stub(channel)
|
| 24 |
+
metadata = (('authorization', 'Key ' + PAT),)
|
| 25 |
+
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
|
| 26 |
|
| 27 |
+
# Make a request to Clarifai API
|
| 28 |
+
post_model_outputs_response = stub.PostModelOutputs(
|
| 29 |
+
service_pb2.PostModelOutputsRequest(
|
| 30 |
+
user_app_id=userDataObject,
|
| 31 |
+
model_id=MODEL_ID,
|
| 32 |
+
version_id=MODEL_VERSION_ID,
|
| 33 |
+
inputs=[
|
| 34 |
+
resources_pb2.Input(
|
| 35 |
+
data=resources_pb2.Data(
|
| 36 |
+
text=resources_pb2.Text(
|
| 37 |
+
raw=raw_text
|
| 38 |
+
)
|
| 39 |
)
|
| 40 |
)
|
| 41 |
+
]
|
| 42 |
+
),
|
| 43 |
+
metadata=metadata
|
| 44 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# Display the generated image if the request is successful
|
| 47 |
+
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
|
| 48 |
+
st.error(f"Clarifai API request failed: {post_model_outputs_response.status.description}")
|
| 49 |
+
else:
|
| 50 |
+
output = post_model_outputs_response.outputs[0].data.image.base64
|
| 51 |
+
st.image(output, caption='Generated Image', use_column_width=True)
|