Spaces:
Runtime error
Runtime error
import streamlit as st | |
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel | |
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc | |
from clarifai_grpc.grpc.api.status import status_code_pb2 | |
# Set your Clarifai credentials and model details | |
PAT = 'bfdeb4029ef54d23a2e608b0aa4c00e4' | |
USER_ID = 'openai' | |
# Streamlit app | |
st.title("AI Integration App") | |
# Choose model type | |
model_type = st.radio("Select Model Type", ["GPT-4 Turbo", "GPT-4 Vision", "DALL-E", "Text-to-Speech"]) | |
# Input text prompt from the user | |
raw_text = st.text_input("Enter a text prompt:", 'I love your product very much') | |
# Button to generate result | |
if st.button("Generate Result"): | |
if model_type == "GPT-4 Turbo": | |
# Connect to Clarifai API for GPT-4 Turbo | |
channel = ClarifaiChannel.get_grpc_channel() | |
stub = service_pb2_grpc.V2Stub(channel) | |
metadata = (('authorization', 'Key ' + PAT),) | |
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id='chat-completion') | |
# Make a request to Clarifai API for GPT-4 Turbo | |
post_model_outputs_response = stub.PostModelOutputs( | |
service_pb2.PostModelOutputsRequest( | |
user_app_id=userDataObject, | |
model_id='gpt-4-turbo', | |
version_id='182136408b4b4002a920fd500839f2c8', | |
inputs=[ | |
resources_pb2.Input( | |
data=resources_pb2.Data( | |
text=resources_pb2.Text( | |
raw=raw_text | |
) | |
) | |
) | |
] | |
), | |
metadata=metadata | |
) | |
# Display the generated result if the request is successful | |
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS: | |
st.error(f"Clarifai API request failed: {post_model_outputs_response.status.description}") | |
else: | |
output = post_model_outputs_response.outputs[0].data.image.base64 | |
st.image(output, caption='Generated Image', use_column_width=True) | |
elif model_type == "GPT-4 Vision": | |
# Connect to Clarifai API for GPT-4 Vision | |
# Replace the following lines with actual GPT-4 Vision logic | |
st.warning("GPT-4 Vision integration code goes here.") | |
elif model_type == "DALL-E": | |
# Connect to Clarifai API for DALL-E | |
# Replace the following lines with actual DALL-E logic | |
st.warning("DALL-E integration code goes here.") | |
elif model_type == "Text-to-Speech": | |
# Connect to Clarifai API for Text-to-Speech | |
# Replace the following lines with actual Text-to-Speech logic | |
st.warning("Text-to-Speech integration code goes here.") | |