matdmiller commited on
Commit
2b9e17f
·
1 Parent(s): 99246a0

close openai connection when done

Browse files
Files changed (2) hide show
  1. app.ipynb +45 -19
  2. app.py +1 -0
app.ipynb CHANGED
@@ -874,6 +874,7 @@
874
  " tokens += response.usage.total_tokens\n",
875
  " # print(json.dumps(messages, indent=4))\n",
876
  "\n",
 
877
  " print('TOKENS CLEANUP:', tokens)\n",
878
  " result = ' '.join([o['content'] for o in messages if o['role'] == 'assistant'])\n",
879
  " \n",
@@ -906,22 +907,10 @@
906
  },
907
  {
908
  "cell_type": "code",
909
- "execution_count": 34,
910
  "id": "e4fb3159-579b-4271-bc96-4cd1e2816eca",
911
  "metadata": {},
912
- "outputs": [
913
- {
914
- "ename": "TypeError",
915
- "evalue": "EventListener._setup.<locals>.event_trigger() got an unexpected keyword argument 'input'",
916
- "output_type": "error",
917
- "traceback": [
918
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
919
- "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
920
- "Cell \u001b[0;32mIn[34], line 35\u001b[0m\n\u001b[1;32m 30\u001b[0m chunks_md \u001b[38;5;241m=\u001b[39m gr\u001b[38;5;241m.\u001b[39mMarkdown(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m,label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mChunks\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 33\u001b[0m \u001b[38;5;66;03m### Define UI Actions ###\u001b[39;00m\n\u001b[0;32m---> 35\u001b[0m \u001b[43mget_url_content_btn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mclick\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mget_page_text\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minput_url\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moutput\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minput_text\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 37\u001b[0m \u001b[38;5;66;03m# input_text \u001b[39;00m\n\u001b[1;32m 38\u001b[0m input_text\u001b[38;5;241m.\u001b[39minput(fn\u001b[38;5;241m=\u001b[39mget_input_text_len, inputs\u001b[38;5;241m=\u001b[39minput_text, outputs\u001b[38;5;241m=\u001b[39minput_text_length)\n",
921
- "\u001b[0;31mTypeError\u001b[0m: EventListener._setup.<locals>.event_trigger() got an unexpected keyword argument 'input'"
922
- ]
923
- }
924
- ],
925
  "source": [
926
  "#| export\n",
927
  "with gr.Blocks(title='TTS', head='TTS', delete_cache=(3600,3600)) as app:\n",
@@ -993,7 +982,7 @@
993
  },
994
  {
995
  "cell_type": "code",
996
- "execution_count": null,
997
  "id": "a00648a1-891b-470b-9959-f5d502055713",
998
  "metadata": {},
999
  "outputs": [],
@@ -1007,10 +996,47 @@
1007
  },
1008
  {
1009
  "cell_type": "code",
1010
- "execution_count": null,
1011
  "id": "4b534fe7-4337-423e-846a-1bdb7cccc4ea",
1012
  "metadata": {},
1013
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1014
  "source": [
1015
  "#| hide\n",
1016
  "#Notebook launch\n",
@@ -1034,7 +1060,7 @@
1034
  },
1035
  {
1036
  "cell_type": "code",
1037
- "execution_count": 33,
1038
  "id": "28e8d888-e790-46fa-bbac-4511b9ab796c",
1039
  "metadata": {},
1040
  "outputs": [
@@ -1064,7 +1090,7 @@
1064
  },
1065
  {
1066
  "cell_type": "code",
1067
- "execution_count": 35,
1068
  "id": "0420310d-930b-4904-8bd4-3458ad8bdbd3",
1069
  "metadata": {},
1070
  "outputs": [],
 
874
  " tokens += response.usage.total_tokens\n",
875
  " # print(json.dumps(messages, indent=4))\n",
876
  "\n",
877
+ " client.close()\n",
878
  " print('TOKENS CLEANUP:', tokens)\n",
879
  " result = ' '.join([o['content'] for o in messages if o['role'] == 'assistant'])\n",
880
  " \n",
 
907
  },
908
  {
909
  "cell_type": "code",
910
+ "execution_count": 35,
911
  "id": "e4fb3159-579b-4271-bc96-4cd1e2816eca",
912
  "metadata": {},
913
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
914
  "source": [
915
  "#| export\n",
916
  "with gr.Blocks(title='TTS', head='TTS', delete_cache=(3600,3600)) as app:\n",
 
982
  },
983
  {
984
  "cell_type": "code",
985
+ "execution_count": 36,
986
  "id": "a00648a1-891b-470b-9959-f5d502055713",
987
  "metadata": {},
988
  "outputs": [],
 
996
  },
997
  {
998
  "cell_type": "code",
999
+ "execution_count": 37,
1000
  "id": "4b534fe7-4337-423e-846a-1bdb7cccc4ea",
1001
  "metadata": {},
1002
+ "outputs": [
1003
+ {
1004
+ "name": "stdout",
1005
+ "output_type": "stream",
1006
+ "text": [
1007
+ "Running on local URL: http://127.0.0.1:7860\n",
1008
+ "\n",
1009
+ "To create a public link, set `share=True` in `launch()`.\n"
1010
+ ]
1011
+ },
1012
+ {
1013
+ "data": {
1014
+ "text/html": [
1015
+ "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
1016
+ ],
1017
+ "text/plain": [
1018
+ "<IPython.core.display.HTML object>"
1019
+ ]
1020
+ },
1021
+ "metadata": {},
1022
+ "output_type": "display_data"
1023
+ },
1024
+ {
1025
+ "data": {
1026
+ "text/plain": []
1027
+ },
1028
+ "execution_count": 37,
1029
+ "metadata": {},
1030
+ "output_type": "execute_result"
1031
+ },
1032
+ {
1033
+ "name": "stdout",
1034
+ "output_type": "stream",
1035
+ "text": [
1036
+ "TOKENS CLEANUP: 970\n"
1037
+ ]
1038
+ }
1039
+ ],
1040
  "source": [
1041
  "#| hide\n",
1042
  "#Notebook launch\n",
 
1060
  },
1061
  {
1062
  "cell_type": "code",
1063
+ "execution_count": 38,
1064
  "id": "28e8d888-e790-46fa-bbac-4511b9ab796c",
1065
  "metadata": {},
1066
  "outputs": [
 
1090
  },
1091
  {
1092
  "cell_type": "code",
1093
+ "execution_count": 40,
1094
  "id": "0420310d-930b-4904-8bd4-3458ad8bdbd3",
1095
  "metadata": {},
1096
  "outputs": [],
app.py CHANGED
@@ -372,6 +372,7 @@ def clean_page_md(text):
372
  tokens += response.usage.total_tokens
373
  # print(json.dumps(messages, indent=4))
374
 
 
375
  print('TOKENS CLEANUP:', tokens)
376
  result = ' '.join([o['content'] for o in messages if o['role'] == 'assistant'])
377
 
 
372
  tokens += response.usage.total_tokens
373
  # print(json.dumps(messages, indent=4))
374
 
375
+ client.close()
376
  print('TOKENS CLEANUP:', tokens)
377
  result = ' '.join([o['content'] for o in messages if o['role'] == 'assistant'])
378