Spaces:
Runtime error
Runtime error
Commit
·
2fb98a5
1
Parent(s):
aad13ce
Upload 2 files
Browse files
app.py
CHANGED
@@ -1,33 +1,15 @@
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
-
|
3 |
-
|
4 |
-
#################################################################################################################
|
5 |
-
# In this section, we set the user authentication, user and app ID, model details, and the prompt text we want
|
6 |
-
# to provide as an input. Change these strings to run your own example.
|
7 |
-
#################################################################################################################
|
8 |
-
|
9 |
-
# Your PAT (Personal Access Token) can be found in the portal under Authentification
|
10 |
PAT = '3ca5bd8b0f2244eb8d0e4b2838fc3cf1'
|
11 |
-
# Specify the correct user_id/app_id pairings
|
12 |
-
# Since you're making inferences outside your app's scope
|
13 |
USER_ID = 'openai'
|
14 |
APP_ID = 'dall-e'
|
15 |
-
# Change these to whatever model and text URL you want to use
|
16 |
MODEL_ID = 'dall-e-3'
|
17 |
MODEL_VERSION_ID = 'dc9dcb6ee67543cebc0b9a025861b868'
|
18 |
RAW_TEXT = 'ocr check mistake with image base with python opencv computer vision help out to know people'
|
19 |
-
# To use a hosted text file, assign the URL variable
|
20 |
-
# TEXT_FILE_URL = 'https://samples.clarifai.com/negative_sentence_12.txt'
|
21 |
-
# Or, to use a local text file, assign the location variable
|
22 |
-
# TEXT_FILE_LOCATION = 'YOUR_TEXT_FILE_LOCATION_HERE'
|
23 |
-
|
24 |
-
############################################################################
|
25 |
-
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
|
26 |
-
############################################################################
|
27 |
-
|
28 |
-
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
|
29 |
-
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
|
30 |
-
from clarifai_grpc.grpc.api.status import status_code_pb2
|
31 |
|
32 |
channel = ClarifaiChannel.get_grpc_channel()
|
33 |
stub = service_pb2_grpc.V2Stub(channel)
|
@@ -36,22 +18,16 @@ metadata = (('authorization', 'Key ' + PAT),)
|
|
36 |
|
37 |
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
|
38 |
|
39 |
-
# To use a local text file, uncomment the following lines
|
40 |
-
# with open(TEXT_FILE_LOCATION, "rb") as f:
|
41 |
-
# file_bytes = f.read()
|
42 |
-
|
43 |
post_model_outputs_response = stub.PostModelOutputs(
|
44 |
service_pb2.PostModelOutputsRequest(
|
45 |
-
user_app_id=userDataObject,
|
46 |
model_id=MODEL_ID,
|
47 |
-
version_id=MODEL_VERSION_ID,
|
48 |
inputs=[
|
49 |
resources_pb2.Input(
|
50 |
data=resources_pb2.Data(
|
51 |
text=resources_pb2.Text(
|
52 |
raw=RAW_TEXT
|
53 |
-
# url=TEXT_FILE_URL
|
54 |
-
# raw=file_bytes
|
55 |
)
|
56 |
)
|
57 |
)
|
@@ -59,14 +35,10 @@ post_model_outputs_response = stub.PostModelOutputs(
|
|
59 |
),
|
60 |
metadata=metadata
|
61 |
)
|
62 |
-
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
|
63 |
-
print(post_model_outputs_response.status)
|
64 |
-
raise Exception("Post model outputs failed, status: " + post_model_outputs_response.status.description)
|
65 |
-
|
66 |
-
# Since we have one input, one output will exist here
|
67 |
-
output = post_model_outputs_response.outputs[0].data.image.base64
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
72 |
|
|
|
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 |
|
6 |
+
# Set your Clarifai credentials and model details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
PAT = '3ca5bd8b0f2244eb8d0e4b2838fc3cf1'
|
|
|
|
|
8 |
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 |
channel = ClarifaiChannel.get_grpc_channel()
|
15 |
stub = service_pb2_grpc.V2Stub(channel)
|
|
|
18 |
|
19 |
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
|
20 |
|
|
|
|
|
|
|
|
|
21 |
post_model_outputs_response = stub.PostModelOutputs(
|
22 |
service_pb2.PostModelOutputsRequest(
|
23 |
+
user_app_id=userDataObject,
|
24 |
model_id=MODEL_ID,
|
25 |
+
version_id=MODEL_VERSION_ID,
|
26 |
inputs=[
|
27 |
resources_pb2.Input(
|
28 |
data=resources_pb2.Data(
|
29 |
text=resources_pb2.Text(
|
30 |
raw=RAW_TEXT
|
|
|
|
|
31 |
)
|
32 |
)
|
33 |
)
|
|
|
35 |
),
|
36 |
metadata=metadata
|
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 |
|