Spaces:
Sleeping
Sleeping
Commit
·
14e6850
1
Parent(s):
11ce9bb
Upload 2 files
Browse files- app.py +58 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Function to make API call and get text completion
|
| 7 |
+
def get_text_completion(raw_text):
|
| 8 |
+
PAT = '9b209aadda08410caf0b6d815b57e080'
|
| 9 |
+
USER_ID = 'openai'
|
| 10 |
+
APP_ID = 'chat-completion'
|
| 11 |
+
MODEL_ID = 'GPT-4'
|
| 12 |
+
MODEL_VERSION_ID = '5d7a50b44aec4a01a9c492c5a5fcf387'
|
| 13 |
+
|
| 14 |
+
channel = ClarifaiChannel.get_grpc_channel()
|
| 15 |
+
stub = service_pb2_grpc.V2Stub(channel)
|
| 16 |
+
metadata = (('authorization', 'Key ' + PAT),)
|
| 17 |
+
|
| 18 |
+
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
|
| 19 |
+
|
| 20 |
+
post_model_outputs_response = stub.PostModelOutputs(
|
| 21 |
+
service_pb2.PostModelOutputsRequest(
|
| 22 |
+
user_app_id=userDataObject,
|
| 23 |
+
model_id=MODEL_ID,
|
| 24 |
+
version_id=MODEL_VERSION_ID,
|
| 25 |
+
inputs=[
|
| 26 |
+
resources_pb2.Input(
|
| 27 |
+
data=resources_pb2.Data(
|
| 28 |
+
text=resources_pb2.Text(
|
| 29 |
+
raw=raw_text
|
| 30 |
+
)
|
| 31 |
+
)
|
| 32 |
+
)
|
| 33 |
+
]
|
| 34 |
+
),
|
| 35 |
+
metadata=metadata
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if post_model_outputs_response.status.code != status_code_pb2.SUCCESS:
|
| 39 |
+
raise Exception(f"Post model outputs failed, status: {post_model_outputs_response.status.description}")
|
| 40 |
+
|
| 41 |
+
output = post_model_outputs_response.outputs[0]
|
| 42 |
+
|
| 43 |
+
return output.data.text.raw
|
| 44 |
+
|
| 45 |
+
# Streamlit app
|
| 46 |
+
def main():
|
| 47 |
+
st.title("Text Completion App")
|
| 48 |
+
|
| 49 |
+
# Get user input
|
| 50 |
+
raw_text = st.text_area("Enter text:", "i need to know about narcotics pemishment")
|
| 51 |
+
|
| 52 |
+
# Perform text completion when button is clicked
|
| 53 |
+
if st.button("Complete Text"):
|
| 54 |
+
completion_result = get_text_completion(raw_text)
|
| 55 |
+
st.success("Completion:\n{}".format(completion_result))
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
clarifai_grpc
|