pyresearch commited on
Commit
aad13ce
·
1 Parent(s): c12d00f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +72 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
34
+
35
+ 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, # The userDataObject is created in the overview and is required when using a PAT
46
+ model_id=MODEL_ID,
47
+ version_id=MODEL_VERSION_ID, # This is optional. Defaults to the latest model version
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
+ )
58
+ ]
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
+ image_filename = f"gen-image.jpg"
70
+ with open(image_filename, 'wb') as f:
71
+ f.write(output)
72
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ clarifai_grpc
3
+