sevdeawesome commited on
Commit
e1ecebc
·
1 Parent(s): 2d5d138
.ipynb_checkpoints/Untitled-checkpoint.ipynb ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [],
3
+ "metadata": {},
4
+ "nbformat": 4,
5
+ "nbformat_minor": 5
6
+ }
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -11,27 +11,16 @@ import os, random
11
  from pathlib import Path
12
  import tiktoken
13
  from getpass import getpass
14
- from rich.markdown import Markdown
15
 
16
  import openai
17
- import wandb
18
- from pprint import pprint
19
- from wandb.integration.openai import autolog
20
  from langchain.text_splitter import MarkdownHeaderTextSplitter
21
  import numpy as np
22
 
23
  from langchain.embeddings import OpenAIEmbeddings
24
- from langchain.vectorstores import Chroma
25
 
26
 
27
 
28
- from tenacity import (
29
- retry,
30
- stop_after_attempt,
31
- wait_random_exponential, # for exponential backoff
32
- )
33
-
34
-
35
 
36
 
37
  if os.getenv("OPENAI_API_KEY") is None:
@@ -43,10 +32,27 @@ if os.getenv("OPENAI_API_KEY") is None:
43
  assert os.getenv("OPENAI_API_KEY", "").startswith("sk-"), "This doesn't look like a valid OpenAI API key"
44
  print("OpenAI API key configured")
45
 
 
 
 
 
46
 
 
 
 
 
 
47
 
 
48
 
 
 
 
 
 
49
 
 
 
50
 
51
  def find_nearest_neighbor(argument="", max_args_in_output=3):
52
  '''
@@ -56,28 +62,7 @@ def find_nearest_neighbor(argument="", max_args_in_output=3):
56
  RETURN the nearest neighbor(s) in vectorDB to argument as string
57
  '''
58
 
59
- md = ""
60
- print(argument)
61
- directory_path = "../../safety_docs"
62
-
63
- for filename in os.listdir(directory_path):
64
- if filename.endswith(".md"):
65
- with open(os.path.join(directory_path, filename), 'r') as file:
66
- content = file.read()
67
- md = md + content
68
-
69
- markdown_document = md
70
-
71
- headers_to_split_on = [
72
- ("#", "Header 1"),
73
- ("##", "Header 2"),
74
- ("###", "Header 3"),
75
- ]
76
-
77
- markdown_splitter = MarkdownHeaderTextSplitter(headers_to_split_on=headers_to_split_on)
78
- md_header_splits = markdown_splitter.split_text(markdown_document)
79
-
80
- embeddings = OpenAIEmbeddings()
81
  embedding_matrix = np.array([embeddings.embed_query(text.page_content) for text in md_header_splits])
82
  argument_embedding = embeddings.embed_query(argument)
83
 
@@ -94,7 +79,7 @@ def find_nearest_neighbor(argument="", max_args_in_output=3):
94
 
95
  return output
96
 
97
- def get_gpt_response(argument, user_prompt, system_prompt=default_config.system_prompt, model=default_config.model_name, n=1, max_tokens=200):
98
  '''
99
  INPUT:
100
  Argument
@@ -103,55 +88,56 @@ def get_gpt_response(argument, user_prompt, system_prompt=default_config.system_
103
  model
104
  '''
105
 
106
- @retry(wait=wait_random_exponential(min=1, max=3), stop=stop_after_attempt(1))
107
- def completion_with_backoff(**kwargs):
108
- return openai.ChatCompletion.create(**kwargs)
109
-
110
  messages=[
111
- {"role": "system", "content": system_prompt},
112
- {"role": "user", "content": user_prompt},
113
- ]
114
- responses = completion_with_backoff(
115
  model=model,
116
  messages=messages,
117
- n = n,
118
  max_tokens=max_tokens
119
- )
120
- for response in responses.choices:
121
- generation = response.message.content
122
- return generation
123
 
124
 
125
- def greet(argument):
126
- nearest_neighbor = find_nearest_neighbor(argument)
 
 
 
 
 
127
  user_prompt = default_config.user_prompt_1 + argument + default_config.user_prompt_2
128
- # response = get_gpt_response(argument, user_prompt)
129
- response = "chatbot response here"
130
- # return "Hello " + "\n We think your argument matches common arguments in our database, is it one of these?:\n " + nearest_neighbor + "\n\n\n ------------------------- \n\n\n Lengthy response: \n" + response
131
- return "english", "german"
132
 
133
- # demo = gr.Interface(
134
- # fn=greet,
135
- # inputs=gr.Textbox(lines=2, placeholder="Anything past 200 tokens (roughly 200 words) will be cutoff. Please enter <=1 paragraph"),
136
- # outputs="text"
137
- # )
138
 
139
- # # demo.queue(max_size=20)
140
- # demo.launch()
141
 
142
 
143
- with gr.Blocks() as demo:
 
 
 
144
  with gr.Row():
145
  with gr.Column():
146
- seed = gr.Text(label="Input Phrase")
147
- english = gr.Text(label="Generated English Text")
148
 
149
  with gr.Column():
150
- german = gr.Text(label="Generated German Text",lines=4)
151
  btn = gr.Button("Generate")
152
- btn.click(greet, inputs=[seed], outputs=[english, german])
153
- gr.Examples(["AGI is far away", "AI is confined to a computer and cannot interact with the physical world", "AI isn't concious"], inputs=[seed])
 
 
 
 
154
 
 
155
  demo.launch()
156
 
157
 
 
11
  from pathlib import Path
12
  import tiktoken
13
  from getpass import getpass
 
14
 
15
  import openai
 
 
 
16
  from langchain.text_splitter import MarkdownHeaderTextSplitter
17
  import numpy as np
18
 
19
  from langchain.embeddings import OpenAIEmbeddings
20
+ # from langchain.vectorstores import Chroma
21
 
22
 
23
 
 
 
 
 
 
 
 
24
 
25
 
26
  if os.getenv("OPENAI_API_KEY") is None:
 
32
  assert os.getenv("OPENAI_API_KEY", "").startswith("sk-"), "This doesn't look like a valid OpenAI API key"
33
  print("OpenAI API key configured")
34
 
35
+ embeddings_model = OpenAIEmbeddings()
36
+
37
+ md = ""
38
+ directory_path = "safety_docs"
39
 
40
+ for filename in os.listdir(directory_path):
41
+ if filename.endswith(".md"):
42
+ with open(os.path.join(directory_path, filename), 'r') as file:
43
+ content = file.read()
44
+ md = md + content
45
 
46
+ markdown_document = md
47
 
48
+ headers_to_split_on = [
49
+ ("#", "Header 1"),
50
+ ("##", "Header 2"),
51
+ ("###", "Header 3"),
52
+ ]
53
 
54
+ markdown_splitter = MarkdownHeaderTextSplitter(headers_to_split_on=headers_to_split_on)
55
+ md_header_splits = markdown_splitter.split_text(markdown_document)
56
 
57
  def find_nearest_neighbor(argument="", max_args_in_output=3):
58
  '''
 
62
  RETURN the nearest neighbor(s) in vectorDB to argument as string
63
  '''
64
 
65
+ embeddings = embeddings_model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  embedding_matrix = np.array([embeddings.embed_query(text.page_content) for text in md_header_splits])
67
  argument_embedding = embeddings.embed_query(argument)
68
 
 
79
 
80
  return output
81
 
82
+ def get_gpt_response(user_prompt, system_prompt=default_config.system_prompt, model=default_config.model_name, n=1, max_tokens=200):
83
  '''
84
  INPUT:
85
  Argument
 
88
  model
89
  '''
90
 
 
 
 
 
91
  messages=[
92
+ {"role": "system", "content": system_prompt},
93
+ {"role": "user", "content": user_prompt},
94
+ ]
95
+ response = openai.ChatCompletion.create(
96
  model=model,
97
  messages=messages,
98
+ n=n,
99
  max_tokens=max_tokens
100
+ )
 
 
 
101
 
102
 
103
+ for choice in response.choices:
104
+ generation = choice.message.content
105
+ return generation
106
+
107
+
108
+ # return the gpt generated response
109
+ def greet1(argument):
110
  user_prompt = default_config.user_prompt_1 + argument + default_config.user_prompt_2
111
+ response = get_gpt_response(user_prompt=user_prompt)
112
+ return response
 
 
113
 
114
+ # return the nearest neighbor arguments
115
+ def greet2(argument):
116
+ nearest_neighbor = find_nearest_neighbor(argument)
117
+ return "Your argument may fall under the common arguments against AI safety. \n Is it one of these? \n " + nearest_neighbor + "\n See the taxonomy of arguments below"
 
118
 
 
 
119
 
120
 
121
+ css = """
122
+ body{background-color:red !important}
123
+ """
124
+ with gr.Blocks(css=css) as demo:
125
  with gr.Row():
126
  with gr.Column():
127
+ seed = gr.Text(label="Explanation / argument for how ASI development will go well")
128
+ english = gr.Text(label="Predicted Argument")
129
 
130
  with gr.Column():
131
+ german = gr.Text(label="AI Generated Response")
132
  btn = gr.Button("Generate")
133
+ btn.click(greet2, inputs=[seed],outputs=english)
134
+ btn.click(greet1, inputs=[seed],outputs=german)
135
+
136
+
137
+ gr.Examples(["AGI is far away", "AI is confined to a computer and cannot interact with the physical world", "AI isn't concious", "If we don't develop AGI, China will!", "If we don't develop AGI, the Americans will!"], inputs=[seed])
138
+
139
 
140
+ demo.queue()
141
  demo.launch()
142
 
143
 
.ipynb_checkpoints/themebuilder-checkpoint.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ import gradio as gr
2
+
3
+ gr.themes.builder()
Untitled.ipynb ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "ac22dd5d-c6b5-4c7a-a7de-67c4c3c5f04b",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Running on local URL: http://127.0.0.1:7861\n",
14
+ "\n",
15
+ "To create a public link, set `share=True` in `launch()`.\n"
16
+ ]
17
+ },
18
+ {
19
+ "data": {
20
+ "text/html": [
21
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
22
+ ],
23
+ "text/plain": [
24
+ "<IPython.core.display.HTML object>"
25
+ ]
26
+ },
27
+ "metadata": {},
28
+ "output_type": "display_data"
29
+ },
30
+ {
31
+ "data": {
32
+ "text/plain": []
33
+ },
34
+ "execution_count": 1,
35
+ "metadata": {},
36
+ "output_type": "execute_result"
37
+ }
38
+ ],
39
+ "source": [
40
+ "import gradio as gr\n",
41
+ "\n",
42
+ "gr.themes.builder(server_port=7861)"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": null,
48
+ "id": "b4c3c6c4-f9f9-477c-af90-9e078e6b3de1",
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": null,
56
+ "id": "d7ea55b9-91d8-486a-9f51-2c927ca98331",
57
+ "metadata": {},
58
+ "outputs": [],
59
+ "source": []
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": null,
64
+ "id": "d4283b3a-07db-4b9e-a45a-383e4523a1de",
65
+ "metadata": {},
66
+ "outputs": [],
67
+ "source": []
68
+ },
69
+ {
70
+ "cell_type": "code",
71
+ "execution_count": 4,
72
+ "id": "c9abfe47-b72e-4205-9dc6-ba63a775adf5",
73
+ "metadata": {},
74
+ "outputs": [
75
+ {
76
+ "data": {
77
+ "text/plain": [
78
+ "\u001b[0;31mInit signature:\u001b[0m\n",
79
+ "\u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthemes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mColor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
80
+ "\u001b[0;34m\u001b[0m \u001b[0mc50\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
81
+ "\u001b[0;34m\u001b[0m \u001b[0mc100\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
82
+ "\u001b[0;34m\u001b[0m \u001b[0mc200\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
83
+ "\u001b[0;34m\u001b[0m \u001b[0mc300\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
84
+ "\u001b[0;34m\u001b[0m \u001b[0mc400\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
85
+ "\u001b[0;34m\u001b[0m \u001b[0mc500\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
86
+ "\u001b[0;34m\u001b[0m \u001b[0mc600\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
87
+ "\u001b[0;34m\u001b[0m \u001b[0mc700\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
88
+ "\u001b[0;34m\u001b[0m \u001b[0mc800\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
89
+ "\u001b[0;34m\u001b[0m \u001b[0mc900\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
90
+ "\u001b[0;34m\u001b[0m \u001b[0mc950\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
91
+ "\u001b[0;34m\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'str | None'\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
92
+ "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
93
+ "\u001b[0;31mDocstring:\u001b[0m <no docstring>\n",
94
+ "\u001b[0;31mSource:\u001b[0m \n",
95
+ "\u001b[0;32mclass\u001b[0m \u001b[0mColor\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
96
+ "\u001b[0;34m\u001b[0m \u001b[0mall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n",
97
+ "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
98
+ "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
99
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
100
+ "\u001b[0;34m\u001b[0m \u001b[0mc50\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
101
+ "\u001b[0;34m\u001b[0m \u001b[0mc100\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
102
+ "\u001b[0;34m\u001b[0m \u001b[0mc200\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
103
+ "\u001b[0;34m\u001b[0m \u001b[0mc300\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
104
+ "\u001b[0;34m\u001b[0m \u001b[0mc400\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
105
+ "\u001b[0;34m\u001b[0m \u001b[0mc500\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
106
+ "\u001b[0;34m\u001b[0m \u001b[0mc600\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
107
+ "\u001b[0;34m\u001b[0m \u001b[0mc700\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
108
+ "\u001b[0;34m\u001b[0m \u001b[0mc800\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
109
+ "\u001b[0;34m\u001b[0m \u001b[0mc900\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
110
+ "\u001b[0;34m\u001b[0m \u001b[0mc950\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
111
+ "\u001b[0;34m\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m|\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
112
+ "\u001b[0;34m\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
113
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc50\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc50\u001b[0m\u001b[0;34m\u001b[0m\n",
114
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc100\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc100\u001b[0m\u001b[0;34m\u001b[0m\n",
115
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc200\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc200\u001b[0m\u001b[0;34m\u001b[0m\n",
116
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc300\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc300\u001b[0m\u001b[0;34m\u001b[0m\n",
117
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc400\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc400\u001b[0m\u001b[0;34m\u001b[0m\n",
118
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc500\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc500\u001b[0m\u001b[0;34m\u001b[0m\n",
119
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc600\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc600\u001b[0m\u001b[0;34m\u001b[0m\n",
120
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc700\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc700\u001b[0m\u001b[0;34m\u001b[0m\n",
121
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc800\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc800\u001b[0m\u001b[0;34m\u001b[0m\n",
122
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc900\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc900\u001b[0m\u001b[0;34m\u001b[0m\n",
123
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc950\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc950\u001b[0m\u001b[0;34m\u001b[0m\n",
124
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\n",
125
+ "\u001b[0;34m\u001b[0m \u001b[0mColor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n",
126
+ "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n",
127
+ "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mexpand\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
128
+ "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\u001b[0m\n",
129
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc50\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
130
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
131
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc200\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
132
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc300\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
133
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc400\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
134
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc500\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
135
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc600\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
136
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc700\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
137
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc800\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
138
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc900\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
139
+ "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc950\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
140
+ "\u001b[0;34m\u001b[0m \u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
141
+ "\u001b[0;31mFile:\u001b[0m ~/anaconda3/lib/python3.10/site-packages/gradio/themes/utils/colors.py\n",
142
+ "\u001b[0;31mType:\u001b[0m type\n",
143
+ "\u001b[0;31mSubclasses:\u001b[0m "
144
+ ]
145
+ },
146
+ "metadata": {},
147
+ "output_type": "display_data"
148
+ }
149
+ ],
150
+ "source": [
151
+ "??gr.themes.monochrome\n",
152
+ "??gr.themes.Color"
153
+ ]
154
+ },
155
+ {
156
+ "cell_type": "code",
157
+ "execution_count": null,
158
+ "id": "c6411099-03cd-4bfa-88a7-e0fda5cd6366",
159
+ "metadata": {},
160
+ "outputs": [],
161
+ "source": [
162
+ "z"
163
+ ]
164
+ }
165
+ ],
166
+ "metadata": {
167
+ "kernelspec": {
168
+ "display_name": "Python 3 (ipykernel)",
169
+ "language": "python",
170
+ "name": "python3"
171
+ },
172
+ "language_info": {
173
+ "codemirror_mode": {
174
+ "name": "ipython",
175
+ "version": 3
176
+ },
177
+ "file_extension": ".py",
178
+ "mimetype": "text/x-python",
179
+ "name": "python",
180
+ "nbconvert_exporter": "python",
181
+ "pygments_lexer": "ipython3",
182
+ "version": "3.10.11"
183
+ }
184
+ },
185
+ "nbformat": 4,
186
+ "nbformat_minor": 5
187
+ }
__pycache__/app.cpython-310.pyc ADDED
Binary file (5.93 kB). View file
 
__pycache__/themebuilder.cpython-310.pyc ADDED
Binary file (205 Bytes). View file
 
app.py CHANGED
@@ -18,7 +18,10 @@ import numpy as np
18
 
19
  from langchain.embeddings import OpenAIEmbeddings
20
  # from langchain.vectorstores import Chroma
21
-
 
 
 
22
 
23
 
24
 
@@ -54,7 +57,7 @@ headers_to_split_on = [
54
  markdown_splitter = MarkdownHeaderTextSplitter(headers_to_split_on=headers_to_split_on)
55
  md_header_splits = markdown_splitter.split_text(markdown_document)
56
 
57
- def find_nearest_neighbor(argument="", max_args_in_output=3):
58
  '''
59
  INPUT:
60
  argument (string)
@@ -114,23 +117,81 @@ def greet1(argument):
114
  # return the nearest neighbor arguments
115
  def greet2(argument):
116
  nearest_neighbor = find_nearest_neighbor(argument)
117
- return "Your argument may fall under the common arguments against AI safety. \n Is it one of these? \n " + nearest_neighbor + "\n See the taxonomy of arguments below"
118
-
119
-
120
- with gr.Blocks(gr.themes.Soft()) as demo:
121
- with gr.Row():
122
- with gr.Column():
123
- seed = gr.Text(label="Explanation / argument for how ASI development will go well")
124
- english = gr.Text(label="Predicted Argument")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  with gr.Column():
127
- german = gr.Text(label="AI Generated Response")
128
  btn = gr.Button("Generate")
129
  btn.click(greet2, inputs=[seed],outputs=english)
130
  btn.click(greet1, inputs=[seed],outputs=german)
131
 
132
 
133
- gr.Examples(["AGI is far away", "AI is confined to a computer and cannot interact with the physical world", "AI isn't concious", "If we don't develop AGI, China will!", "If we don't develop AGI, the Americans will!"], inputs=[seed])
134
 
135
 
136
  demo.queue()
 
18
 
19
  from langchain.embeddings import OpenAIEmbeddings
20
  # from langchain.vectorstores import Chroma
21
+ from typing import Iterable
22
+ from gradio.themes.base import Base
23
+ from gradio.themes.utils import colors, fonts, sizes
24
+ import time
25
 
26
 
27
 
 
57
  markdown_splitter = MarkdownHeaderTextSplitter(headers_to_split_on=headers_to_split_on)
58
  md_header_splits = markdown_splitter.split_text(markdown_document)
59
 
60
+ def find_nearest_neighbor(argument="", max_args_in_output=2):
61
  '''
62
  INPUT:
63
  argument (string)
 
117
  # return the nearest neighbor arguments
118
  def greet2(argument):
119
  nearest_neighbor = find_nearest_neighbor(argument)
120
+ return "Your argument may fall under the common arguments against AI safety. \nIs it one of these? \n" + nearest_neighbor + "\nSee the taxonomy of arguments below"
121
+
122
+
123
+
124
+
125
+ # theme = gr.themes.Monochrome()
126
+ theme = gr.themes.Monochrome(
127
+ # neutral_hue=gr.themes.colors.red,
128
+
129
+ # n, boxes, text, nothing bottom text most text
130
+ neutral_hue=gr.themes.Color("red", "#636363", "#636363", "lightgrey", "lightgrey", "lightgrey", "lightgrey", "grey", "red", "#636363", "red"),
131
+ primary_hue=gr.themes.Color("#8c0010", "#8c0010", "#8c0010", "#8c0010", "#8c0010", "#8c0010", "#8c0010", "#8c0010", "#8c0010", "#8c0010", "#8c0010"),
132
+ secondary_hue=gr.themes.Color("white", "white", "white", "white", "white", "white", "white", "white", "white", "white", "white"),
133
+ )
134
+
135
+
136
+ theme = theme.set(
137
+ body_background_fill="black",
138
+ block_title_background_fill="black",
139
+ block_background_fill="black",
140
+ body_text_color="white",
141
+ link_text_color='*primary_50',
142
+ link_text_color_dark='*primary_50',
143
+ link_text_color_active='*primary_50',
144
+ link_text_color_active_dark='*primary_50',
145
+ link_text_color_hover='*primary_50',
146
+ link_text_color_hover_dark='*primary_50',
147
+ link_text_color_visited='*primary_50',
148
+ link_text_color_visited_dark='*primary_50'
149
+ )
150
+
151
+ css_string = """
152
+ @import url('https://fonts.googleapis.com/css2?family=Gabarito&family=Gothic+A1:wght@100;200;300;400;500;600;700;800;900&display=swap');
153
+ # .gradio-container *{
154
+ # background-color: black !important;
155
+ # color: white !important;
156
+ # font-family: 'Gabarito', cursive !important;
157
+ # }
158
+
159
+
160
+ # .block > *{
161
+ # background: black !important;
162
+ # color: white !important;
163
+ # }
164
+
165
+
166
+ force_black_bg {
167
+ background-color: blue !important;
168
+ color: white !important;
169
+ font-family: 'Gabarito', cursive !important;
170
+ }
171
+ force_black_bg *{
172
+ background-color: blue !important;
173
+ color: white !important;
174
+ font-family: 'Gabarito', cursive !important;
175
+ }
176
+
177
+ """
178
+ css_string2 = ""
179
+
180
+ with gr.Blocks(theme=theme, css=css_string2) as demo:
181
+ with gr.Row(elem_id="force_black_bg"):
182
+ with gr.Column(elem_id="force_black_bg"):
183
+ seed = gr.Text( label="AI Safety Skepticism: What's Your Take?", placeholder="Enter an argument or something you'd like to say!")
184
+ # make a version of english with placeholder text
185
+ english = gr.Text(elem_id="themed_question_box", label="Common Argument Classifier")
186
 
187
  with gr.Column():
188
+ german = gr.Text(label="Safetybot Response")
189
  btn = gr.Button("Generate")
190
  btn.click(greet2, inputs=[seed],outputs=english)
191
  btn.click(greet1, inputs=[seed],outputs=german)
192
 
193
 
194
+ gr.Examples(["AGI is far away, I'm not worried", "AI is confined to a computer and cannot interact with the physical world", "AI isn't concious", "If we don't develop AGI, China will!", "If we don't develop AGI, the Americans will!"], inputs=[seed])
195
 
196
 
197
  demo.queue()
fe/index.html ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Document</title>
7
+ </head>
8
+
9
+ <style>
10
+ body{
11
+ background-color: aqua;
12
+ }
13
+ </style>
14
+ <body>
15
+ <iframe src="https://sevdeawesome-safetybot.hf.space"
16
+ frameborder="0"
17
+ width="850"
18
+ height="450"></iframe>
19
+
20
+ </body>
21
+ </html>
index.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ body{
2
+ background: blue;
3
+ }
themebuilder.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ import gradio as gr
2
+
3
+ gr.themes.builder()