Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ 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 for
|
7 |
PAT_GPT4 = '3ca5bd8b0f2244eb8d0e4b2838fc3cf1'
|
8 |
USER_ID_GPT4 = 'openai'
|
9 |
APP_ID_GPT4 = 'chat-completion'
|
@@ -54,14 +54,14 @@ image_upload = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
|
54 |
|
55 |
# Button to generate result
|
56 |
if st.button("NewsGuardian News Result"):
|
57 |
-
if model_type == "
|
58 |
-
# Set up gRPC channel for
|
59 |
channel_gpt4 = ClarifaiChannel.get_grpc_channel()
|
60 |
stub_gpt4 = service_pb2_grpc.V2Stub(channel_gpt4)
|
61 |
metadata_gpt4 = (('authorization', 'Key ' + PAT_GPT4),)
|
62 |
userDataObject_gpt4 = resources_pb2.UserAppIDSet(user_id=USER_ID_GPT4, app_id=APP_ID_GPT4)
|
63 |
|
64 |
-
# Prepare the request for
|
65 |
input_data_gpt4 = resources_pb2.Data()
|
66 |
|
67 |
if raw_text:
|
@@ -81,16 +81,16 @@ if st.button("NewsGuardian News Result"):
|
|
81 |
metadata=metadata_gpt4 # Use metadata directly in the gRPC request
|
82 |
)
|
83 |
|
84 |
-
# Check if the request was successful for
|
85 |
if post_model_outputs_response_gpt4.status.code != status_code_pb2.SUCCESS:
|
86 |
-
st.error(f"
|
87 |
else:
|
88 |
-
# Get the output for
|
89 |
output_gpt4 = post_model_outputs_response_gpt4.outputs[0].data
|
90 |
|
91 |
-
# Display the result for
|
92 |
if output_gpt4.HasField("image"):
|
93 |
-
st.image(output_gpt4.image.base64, caption='Generated Image (
|
94 |
elif output_gpt4.HasField("text"):
|
95 |
# Display the text result
|
96 |
st.text(output_gpt4.text.raw)
|
|
|
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 for NewsGuardian model
|
7 |
PAT_GPT4 = '3ca5bd8b0f2244eb8d0e4b2838fc3cf1'
|
8 |
USER_ID_GPT4 = 'openai'
|
9 |
APP_ID_GPT4 = 'chat-completion'
|
|
|
54 |
|
55 |
# Button to generate result
|
56 |
if st.button("NewsGuardian News Result"):
|
57 |
+
if model_type == "NewsGuardian model":
|
58 |
+
# Set up gRPC channel for NewsGuardian model
|
59 |
channel_gpt4 = ClarifaiChannel.get_grpc_channel()
|
60 |
stub_gpt4 = service_pb2_grpc.V2Stub(channel_gpt4)
|
61 |
metadata_gpt4 = (('authorization', 'Key ' + PAT_GPT4),)
|
62 |
userDataObject_gpt4 = resources_pb2.UserAppIDSet(user_id=USER_ID_GPT4, app_id=APP_ID_GPT4)
|
63 |
|
64 |
+
# Prepare the request for NewsGuardian model
|
65 |
input_data_gpt4 = resources_pb2.Data()
|
66 |
|
67 |
if raw_text:
|
|
|
81 |
metadata=metadata_gpt4 # Use metadata directly in the gRPC request
|
82 |
)
|
83 |
|
84 |
+
# Check if the request was successful for NewsGuardian model
|
85 |
if post_model_outputs_response_gpt4.status.code != status_code_pb2.SUCCESS:
|
86 |
+
st.error(f"NewsGuardian model API request failed: {post_model_outputs_response_gpt4.status.description}")
|
87 |
else:
|
88 |
+
# Get the output for NewsGuardian model
|
89 |
output_gpt4 = post_model_outputs_response_gpt4.outputs[0].data
|
90 |
|
91 |
+
# Display the result for NewsGuardian model
|
92 |
if output_gpt4.HasField("image"):
|
93 |
+
st.image(output_gpt4.image.base64, caption='Generated Image (NewsGuardian model)', use_column_width=True)
|
94 |
elif output_gpt4.HasField("text"):
|
95 |
# Display the text result
|
96 |
st.text(output_gpt4.text.raw)
|