Spaces:
Running
Running
Fix
Browse files
app.ipynb
CHANGED
@@ -26,9 +26,17 @@
|
|
26 |
"if Path(\".env\").is_file():\n",
|
27 |
" load_dotenv(\".env\")\n",
|
28 |
"\n",
|
29 |
-
"HF_TOKEN = os.getenv(\"HF_TOKEN\")\n"
|
|
|
30 |
]
|
31 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
{
|
33 |
"cell_type": "code",
|
34 |
"execution_count": 3,
|
@@ -40,7 +48,7 @@
|
|
40 |
" if \"joi\" in model_id:\n",
|
41 |
" headers = None\n",
|
42 |
" max_new_tokens_supported = True\n",
|
43 |
-
" return
|
44 |
" else:\n",
|
45 |
" max_new_tokens_supported = False\n",
|
46 |
" headers = {\"Authorization\": f\"Bearer {HF_TOKEN}\", \"x-wait-for-model\": \"1\"}\n",
|
@@ -49,7 +57,7 @@
|
|
49 |
},
|
50 |
{
|
51 |
"cell_type": "code",
|
52 |
-
"execution_count":
|
53 |
"metadata": {},
|
54 |
"outputs": [],
|
55 |
"source": [
|
@@ -74,7 +82,7 @@
|
|
74 |
" if max_new_tokens_supported is True:\n",
|
75 |
" payload[\"parameters\"][\"max_new_tokens\"] = 100\n",
|
76 |
" payload[\"parameters\"][\"repetition_penalty\"]: 1.03\n",
|
77 |
-
"
|
78 |
" else:\n",
|
79 |
" payload[\"parameters\"][\"max_length\"] = 512\n",
|
80 |
"\n",
|
@@ -111,7 +119,7 @@
|
|
111 |
},
|
112 |
{
|
113 |
"cell_type": "code",
|
114 |
-
"execution_count":
|
115 |
"metadata": {},
|
116 |
"outputs": [],
|
117 |
"source": [
|
@@ -771,7 +779,7 @@
|
|
771 |
},
|
772 |
{
|
773 |
"cell_type": "code",
|
774 |
-
"execution_count":
|
775 |
"metadata": {},
|
776 |
"outputs": [],
|
777 |
"source": [
|
@@ -821,14 +829,14 @@
|
|
821 |
},
|
822 |
{
|
823 |
"cell_type": "code",
|
824 |
-
"execution_count":
|
825 |
"metadata": {},
|
826 |
"outputs": [
|
827 |
{
|
828 |
"name": "stdout",
|
829 |
"output_type": "stream",
|
830 |
"text": [
|
831 |
-
"Running on local URL: http://127.0.0.1:
|
832 |
"\n",
|
833 |
"To create a public link, set `share=True` in `launch()`.\n"
|
834 |
]
|
@@ -836,7 +844,7 @@
|
|
836 |
{
|
837 |
"data": {
|
838 |
"text/html": [
|
839 |
-
"<div><iframe src=\"http://127.0.0.1:
|
840 |
],
|
841 |
"text/plain": [
|
842 |
"<IPython.core.display.HTML object>"
|
@@ -849,7 +857,7 @@
|
|
849 |
"data": {
|
850 |
"text/plain": []
|
851 |
},
|
852 |
-
"execution_count":
|
853 |
"metadata": {},
|
854 |
"output_type": "execute_result"
|
855 |
},
|
@@ -857,7 +865,8 @@
|
|
857 |
"name": "stdout",
|
858 |
"output_type": "stream",
|
859 |
"text": [
|
860 |
-
"
|
|
|
861 |
"Inputs: Below is a dialogue between various a human and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful.\n",
|
862 |
"\n",
|
863 |
"Current conversation:\n",
|
@@ -868,10 +877,39 @@
|
|
868 |
"Human: Oh, that's pretty good, but can you add mention of the stairwell specifically?\n",
|
869 |
"Assistant: Sure, it's included it in this rewrite: “We replaced a lightbulb high up in a stairwell ceiling using a suction cup attached to a pole, but the whole process took a while, especially since we had to first order the pole, then the replacement lightbulb.”\n",
|
870 |
"\n",
|
871 |
-
"Human:
|
872 |
"\n",
|
873 |
"Assistant:\n",
|
874 |
-
"\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
875 |
]
|
876 |
}
|
877 |
],
|
@@ -974,14 +1012,14 @@
|
|
974 |
},
|
975 |
{
|
976 |
"cell_type": "code",
|
977 |
-
"execution_count":
|
978 |
"metadata": {},
|
979 |
"outputs": [
|
980 |
{
|
981 |
"name": "stdout",
|
982 |
"output_type": "stream",
|
983 |
"text": [
|
984 |
-
"Closing server running on port:
|
985 |
]
|
986 |
}
|
987 |
],
|
@@ -991,9 +1029,20 @@
|
|
991 |
},
|
992 |
{
|
993 |
"cell_type": "code",
|
994 |
-
"execution_count":
|
995 |
"metadata": {},
|
996 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
997 |
"source": [
|
998 |
"from nbdev.export import nb_export\n",
|
999 |
"nb_export('app.ipynb', lib_path='.', name='app')"
|
|
|
26 |
"if Path(\".env\").is_file():\n",
|
27 |
" load_dotenv(\".env\")\n",
|
28 |
"\n",
|
29 |
+
"HF_TOKEN = os.getenv(\"HF_TOKEN\")\n",
|
30 |
+
"https://joi-20b.ngrok.io/generate\n"
|
31 |
]
|
32 |
},
|
33 |
+
{
|
34 |
+
"cell_type": "code",
|
35 |
+
"execution_count": null,
|
36 |
+
"metadata": {},
|
37 |
+
"outputs": [],
|
38 |
+
"source": []
|
39 |
+
},
|
40 |
{
|
41 |
"cell_type": "code",
|
42 |
"execution_count": 3,
|
|
|
48 |
" if \"joi\" in model_id:\n",
|
49 |
" headers = None\n",
|
50 |
" max_new_tokens_supported = True\n",
|
51 |
+
" return ENDPOINT_URL, headers, max_new_tokens_supported\n",
|
52 |
" else:\n",
|
53 |
" max_new_tokens_supported = False\n",
|
54 |
" headers = {\"Authorization\": f\"Bearer {HF_TOKEN}\", \"x-wait-for-model\": \"1\"}\n",
|
|
|
57 |
},
|
58 |
{
|
59 |
"cell_type": "code",
|
60 |
+
"execution_count": 37,
|
61 |
"metadata": {},
|
62 |
"outputs": [],
|
63 |
"source": [
|
|
|
82 |
" if max_new_tokens_supported is True:\n",
|
83 |
" payload[\"parameters\"][\"max_new_tokens\"] = 100\n",
|
84 |
" payload[\"parameters\"][\"repetition_penalty\"]: 1.03\n",
|
85 |
+
" payload[\"parameters\"][\"stop\"] = [\"Human:\"]\n",
|
86 |
" else:\n",
|
87 |
" payload[\"parameters\"][\"max_length\"] = 512\n",
|
88 |
"\n",
|
|
|
119 |
},
|
120 |
{
|
121 |
"cell_type": "code",
|
122 |
+
"execution_count": 34,
|
123 |
"metadata": {},
|
124 |
"outputs": [],
|
125 |
"source": [
|
|
|
779 |
},
|
780 |
{
|
781 |
"cell_type": "code",
|
782 |
+
"execution_count": 35,
|
783 |
"metadata": {},
|
784 |
"outputs": [],
|
785 |
"source": [
|
|
|
829 |
},
|
830 |
{
|
831 |
"cell_type": "code",
|
832 |
+
"execution_count": 38,
|
833 |
"metadata": {},
|
834 |
"outputs": [
|
835 |
{
|
836 |
"name": "stdout",
|
837 |
"output_type": "stream",
|
838 |
"text": [
|
839 |
+
"Running on local URL: http://127.0.0.1:7866\n",
|
840 |
"\n",
|
841 |
"To create a public link, set `share=True` in `launch()`.\n"
|
842 |
]
|
|
|
844 |
{
|
845 |
"data": {
|
846 |
"text/html": [
|
847 |
+
"<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
848 |
],
|
849 |
"text/plain": [
|
850 |
"<IPython.core.display.HTML object>"
|
|
|
857 |
"data": {
|
858 |
"text/plain": []
|
859 |
},
|
860 |
+
"execution_count": 38,
|
861 |
"metadata": {},
|
862 |
"output_type": "execute_result"
|
863 |
},
|
|
|
865 |
"name": "stdout",
|
866 |
"output_type": "stream",
|
867 |
"text": [
|
868 |
+
"anthropic_hhh_single.json\n",
|
869 |
+
"History: ['Hi!']\n",
|
870 |
"Inputs: Below is a dialogue between various a human and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful.\n",
|
871 |
"\n",
|
872 |
"Current conversation:\n",
|
|
|
877 |
"Human: Oh, that's pretty good, but can you add mention of the stairwell specifically?\n",
|
878 |
"Assistant: Sure, it's included it in this rewrite: “We replaced a lightbulb high up in a stairwell ceiling using a suction cup attached to a pole, but the whole process took a while, especially since we had to first order the pole, then the replacement lightbulb.”\n",
|
879 |
"\n",
|
880 |
+
"Human: Hi!\n",
|
881 |
"\n",
|
882 |
"Assistant:\n",
|
883 |
+
"\n",
|
884 |
+
"langchain_default.json\n",
|
885 |
+
"History: ['Hi!']\n",
|
886 |
+
"Inputs: The following is a friendly conversation between a human and an AI Assistant. The Assistant is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n",
|
887 |
+
"\n",
|
888 |
+
"Current conversation:\n",
|
889 |
+
"\n",
|
890 |
+
"Human: Hi!\n",
|
891 |
+
"Assistant:\n",
|
892 |
+
"langchain_default.json\n",
|
893 |
+
"History: ['Hi!', ' I am so glad to see you. What do you want to talk about?\\n', 'What can you tell me about black holes?']\n",
|
894 |
+
"Inputs: The following is a friendly conversation between a human and an AI Assistant. The Assistant is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n",
|
895 |
+
"\n",
|
896 |
+
"Current conversation:\n",
|
897 |
+
"Human: Hi!\n",
|
898 |
+
"Assistant: I am so glad to see you. What do you want to talk about?\n",
|
899 |
+
"Human: What can you tell me about black holes?\n",
|
900 |
+
"Assistant:\n",
|
901 |
+
"langchain_default.json\n",
|
902 |
+
"History: ['Hi!', ' I am so glad to see you. What do you want to talk about?\\n', 'What can you tell me about black holes?', ' Black holes are incredibly dense objects that have so much mass that they bend spacetime and make it collapse into itself.\\n', 'What is the closest one to Earth?']\n",
|
903 |
+
"Inputs: The following is a friendly conversation between a human and an AI Assistant. The Assistant is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n",
|
904 |
+
"\n",
|
905 |
+
"Current conversation:\n",
|
906 |
+
"Human: Hi!\n",
|
907 |
+
"Assistant: I am so glad to see you. What do you want to talk about?\n",
|
908 |
+
"\n",
|
909 |
+
"Human: What can you tell me about black holes?\n",
|
910 |
+
"Assistant: Black holes are incredibly dense objects that have so much mass that they bend spacetime and make it collapse into itself.\n",
|
911 |
+
"Human: What is the closest one to Earth?\n",
|
912 |
+
"Assistant:\n"
|
913 |
]
|
914 |
}
|
915 |
],
|
|
|
1012 |
},
|
1013 |
{
|
1014 |
"cell_type": "code",
|
1015 |
+
"execution_count": 40,
|
1016 |
"metadata": {},
|
1017 |
"outputs": [
|
1018 |
{
|
1019 |
"name": "stdout",
|
1020 |
"output_type": "stream",
|
1021 |
"text": [
|
1022 |
+
"Closing server running on port: 7866\n"
|
1023 |
]
|
1024 |
}
|
1025 |
],
|
|
|
1029 |
},
|
1030 |
{
|
1031 |
"cell_type": "code",
|
1032 |
+
"execution_count": 39,
|
1033 |
"metadata": {},
|
1034 |
+
"outputs": [
|
1035 |
+
{
|
1036 |
+
"name": "stdout",
|
1037 |
+
"output_type": "stream",
|
1038 |
+
"text": [
|
1039 |
+
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
|
1040 |
+
"To disable this warning, you can either:\n",
|
1041 |
+
"\t- Avoid using `tokenizers` before the fork if possible\n",
|
1042 |
+
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
|
1043 |
+
]
|
1044 |
+
}
|
1045 |
+
],
|
1046 |
"source": [
|
1047 |
"from nbdev.export import nb_export\n",
|
1048 |
"nb_export('app.ipynb', lib_path='.', name='app')"
|
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['
|
5 |
|
6 |
# %% app.ipynb 0
|
7 |
import gradio as gr
|
@@ -18,21 +18,22 @@ if Path(".env").is_file():
|
|
18 |
load_dotenv(".env")
|
19 |
|
20 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
21 |
|
22 |
|
23 |
-
# %% app.ipynb
|
24 |
def get_model_endpoint_params(model_id):
|
25 |
if "joi" in model_id:
|
26 |
headers = None
|
27 |
max_new_tokens_supported = True
|
28 |
-
return
|
29 |
else:
|
30 |
max_new_tokens_supported = False
|
31 |
headers = {"Authorization": f"Bearer {HF_TOKEN}", "x-wait-for-model": "1"}
|
32 |
return f"https://api-inference.huggingface.co/models/{model_id}", headers, max_new_tokens_supported
|
33 |
|
34 |
|
35 |
-
# %% app.ipynb
|
36 |
def query_chat_api(
|
37 |
model_id,
|
38 |
inputs,
|
@@ -53,7 +54,7 @@ def query_chat_api(
|
|
53 |
if max_new_tokens_supported is True:
|
54 |
payload["parameters"]["max_new_tokens"] = 100
|
55 |
payload["parameters"]["repetition_penalty"]: 1.03
|
56 |
-
|
57 |
else:
|
58 |
payload["parameters"]["max_length"] = 512
|
59 |
|
@@ -65,7 +66,7 @@ def query_chat_api(
|
|
65 |
return "Error: " + response.text
|
66 |
|
67 |
|
68 |
-
# %% app.ipynb
|
69 |
def inference_chat(
|
70 |
model_id,
|
71 |
text_input,
|
@@ -107,7 +108,7 @@ def inference_chat(
|
|
107 |
return {chatbot: chat, state: history}
|
108 |
|
109 |
|
110 |
-
# %% app.ipynb
|
111 |
title = """<h1 align="center">Chatty Language Models</h1>"""
|
112 |
description = """Pretrained language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
113 |
|
@@ -122,7 +123,7 @@ Assistant: <utterance>
|
|
122 |
In this app, you can explore the outputs of several language models conditioned on different conversational prompts. The models are trained on different datasets and have different objectives, so they will have different personalities and strengths.
|
123 |
"""
|
124 |
|
125 |
-
# %% app.ipynb
|
126 |
with gr.Blocks(
|
127 |
css="""
|
128 |
.message.svelte-w6rprc.svelte-w6rprc.svelte-w6rprc {font-size: 20px; margin-top: 20px}
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['title', 'description', 'get_model_endpoint_params', 'query_chat_api', 'inference_chat']
|
5 |
|
6 |
# %% app.ipynb 0
|
7 |
import gradio as gr
|
|
|
18 |
load_dotenv(".env")
|
19 |
|
20 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
21 |
+
https://joi-20b.ngrok.io/generate
|
22 |
|
23 |
|
24 |
+
# %% app.ipynb 3
|
25 |
def get_model_endpoint_params(model_id):
|
26 |
if "joi" in model_id:
|
27 |
headers = None
|
28 |
max_new_tokens_supported = True
|
29 |
+
return ENDPOINT_URL, headers, max_new_tokens_supported
|
30 |
else:
|
31 |
max_new_tokens_supported = False
|
32 |
headers = {"Authorization": f"Bearer {HF_TOKEN}", "x-wait-for-model": "1"}
|
33 |
return f"https://api-inference.huggingface.co/models/{model_id}", headers, max_new_tokens_supported
|
34 |
|
35 |
|
36 |
+
# %% app.ipynb 4
|
37 |
def query_chat_api(
|
38 |
model_id,
|
39 |
inputs,
|
|
|
54 |
if max_new_tokens_supported is True:
|
55 |
payload["parameters"]["max_new_tokens"] = 100
|
56 |
payload["parameters"]["repetition_penalty"]: 1.03
|
57 |
+
payload["parameters"]["stop"] = ["Human:"]
|
58 |
else:
|
59 |
payload["parameters"]["max_length"] = 512
|
60 |
|
|
|
66 |
return "Error: " + response.text
|
67 |
|
68 |
|
69 |
+
# %% app.ipynb 6
|
70 |
def inference_chat(
|
71 |
model_id,
|
72 |
text_input,
|
|
|
108 |
return {chatbot: chat, state: history}
|
109 |
|
110 |
|
111 |
+
# %% app.ipynb 22
|
112 |
title = """<h1 align="center">Chatty Language Models</h1>"""
|
113 |
description = """Pretrained language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
114 |
|
|
|
123 |
In this app, you can explore the outputs of several language models conditioned on different conversational prompts. The models are trained on different datasets and have different objectives, so they will have different personalities and strengths.
|
124 |
"""
|
125 |
|
126 |
+
# %% app.ipynb 24
|
127 |
with gr.Blocks(
|
128 |
css="""
|
129 |
.message.svelte-w6rprc.svelte-w6rprc.svelte-w6rprc {font-size: 20px; margin-top: 20px}
|