File size: 1,947 Bytes
2fb98a5
 
 
 
aad13ce
2fb98a5
aad13ce
 
 
 
 
 
e65180f
 
aad13ce
e65180f
 
aad13ce
e65180f
 
 
 
 
 
 
aad13ce
e65180f
 
 
 
 
 
 
 
 
 
 
 
aad13ce
 
e65180f
 
 
 
aad13ce
e65180f
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
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
40
41
42
43
44
45
46
47
48
49
50
51
52
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 = '3ca5bd8b0f2244eb8d0e4b2838fc3cf1'
USER_ID = 'openai'
APP_ID = 'dall-e'
MODEL_ID = 'dall-e-3'
MODEL_VERSION_ID = 'dc9dcb6ee67543cebc0b9a025861b868'

# Streamlit app
st.title("Pyresearch Image Generator")

# Input text prompt from the user
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')

# Button to generate image
if st.button("Generate Image"):
    # Connect to Clarifai API
    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=APP_ID)

    # Make a request to Clarifai API
    post_model_outputs_response = stub.PostModelOutputs(
        service_pb2.PostModelOutputsRequest(
            user_app_id=userDataObject,
            model_id=MODEL_ID,
            version_id=MODEL_VERSION_ID,
            inputs=[
                resources_pb2.Input(
                    data=resources_pb2.Data(
                        text=resources_pb2.Text(
                            raw=raw_text
                        )
                    )
                )
            ]
        ),
        metadata=metadata
    )

    # Display the generated image 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)