Spaces:
Runtime error
Runtime error
Update app.py
#3
by
pyresearch
- opened
app.py
CHANGED
@@ -1,67 +1,58 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
import
|
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 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
btn_gen.click(fn=my_chatgpt.chat, inputs=prompt,
|
61 |
-
outputs=res)
|
62 |
-
btn_clear.click(fn=my_chatgpt.reset,
|
63 |
-
inputs=[prompt, res],
|
64 |
-
outputs=[prompt, res])
|
65 |
-
|
66 |
-
demo.queue()
|
67 |
-
demo.launch()
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|