Haofei Yu
commited on
Commit
•
a9c1d92
1
Parent(s):
65f668d
pre-commit checking (#18)
Browse files* support pre-commit
* support running
* pre-commit running
* pre-commit running
- .gitignore +1 -1
- .pre-commit-config.yaml +1 -1
- app.py +40 -24
- ctm/ctms/ctm_base.py +3 -1
- requirements.txt +2 -1
.gitignore
CHANGED
@@ -157,4 +157,4 @@ cython_debug/
|
|
157 |
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
-
#.idea/
|
|
|
157 |
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
.pre-commit-config.yaml
CHANGED
@@ -24,4 +24,4 @@ repos:
|
|
24 |
- repo: https://github.com/kynan/nbstripout
|
25 |
rev: 0.6.0
|
26 |
hooks:
|
27 |
-
- id: nbstripout
|
|
|
24 |
- repo: https://github.com/kynan/nbstripout
|
25 |
rev: 0.6.0
|
26 |
hooks:
|
27 |
+
- id: nbstripout
|
app.py
CHANGED
@@ -2,8 +2,8 @@ import os
|
|
2 |
import sys
|
3 |
|
4 |
import gradio as gr
|
5 |
-
|
6 |
-
sys.path.append(
|
7 |
from ctm.ctms.ctm_base import BaseConsciousnessTuringMachine
|
8 |
|
9 |
ctm = BaseConsciousnessTuringMachine()
|
@@ -17,27 +17,27 @@ def convert_base64(image_array):
|
|
17 |
buffer = io.BytesIO()
|
18 |
image.save(buffer, format="PNG")
|
19 |
byte_data = buffer.getvalue()
|
20 |
-
base64_string = base64.b64encode(byte_data).decode(
|
21 |
return base64_string
|
22 |
|
23 |
|
24 |
def introduction():
|
25 |
with gr.Column(scale=2):
|
26 |
-
gr.Image(
|
27 |
-
"images/CTM-AI.png", elem_id="banner-image", show_label=False
|
28 |
-
)
|
29 |
with gr.Column(scale=5):
|
30 |
gr.Markdown(
|
31 |
"""Consciousness Turing Machine Demo
|
32 |
"""
|
33 |
)
|
34 |
|
|
|
35 |
def add_processor(processor_name, display_name, state):
|
36 |
-
print(
|
37 |
ctm.add_processor(processor_name)
|
38 |
print(ctm.processor_group_map)
|
39 |
print(len(ctm.processor_list))
|
40 |
-
return display_name +
|
|
|
41 |
|
42 |
def processor_tab():
|
43 |
# Categorized model names
|
@@ -45,14 +45,14 @@ def processor_tab():
|
|
45 |
"gpt4_text_emotion_processor",
|
46 |
"gpt4_text_summary_processor",
|
47 |
"gpt4_speaker_intent_processor",
|
48 |
-
"roberta_text_sentiment_processor"
|
49 |
]
|
50 |
vision_processors = [
|
51 |
"gpt4v_cloth_fashion_processor",
|
52 |
"gpt4v_face_emotion_processor",
|
53 |
"gpt4v_ocr_processor",
|
54 |
"gpt4v_posture",
|
55 |
-
"gpt4v_scene_location_processor"
|
56 |
]
|
57 |
|
58 |
with gr.Blocks():
|
@@ -60,37 +60,53 @@ def processor_tab():
|
|
60 |
with gr.Column(scale=1):
|
61 |
gr.Markdown("### Text Processors")
|
62 |
for model_name in text_processors:
|
63 |
-
display_name =
|
|
|
|
|
|
|
|
|
64 |
|
65 |
button = gr.Button(display_name)
|
66 |
-
processor_name = gr.Textbox(
|
67 |
-
|
|
|
|
|
|
|
|
|
68 |
button.click(
|
69 |
fn=add_processor,
|
70 |
inputs=[processor_name, display_name, gr.State()],
|
71 |
-
outputs=[button]
|
72 |
)
|
73 |
|
74 |
with gr.Column(scale=1):
|
75 |
gr.Markdown("### Vision Processors")
|
76 |
for model_name in vision_processors:
|
77 |
-
display_name =
|
|
|
|
|
|
|
|
|
78 |
|
79 |
button = gr.Button(display_name)
|
80 |
-
processor_name = gr.Textbox(
|
81 |
-
|
|
|
|
|
|
|
|
|
82 |
button.click(
|
83 |
fn=add_processor,
|
84 |
inputs=[processor_name, display_name, gr.State()],
|
85 |
-
outputs=[button]
|
86 |
)
|
87 |
|
88 |
|
89 |
-
|
90 |
-
|
91 |
def forward(query, content, image, state):
|
92 |
-
state[
|
93 |
-
ask_processors_output_info, state = ask_processors(
|
|
|
|
|
94 |
uptree_competition_output_info, state = uptree_competition(state)
|
95 |
ask_supervisor_output_info, state = ask_supervisor(state)
|
96 |
|
@@ -148,8 +164,8 @@ def interface_tab():
|
|
148 |
text = gr.Textbox(label="Enter your text here")
|
149 |
query = gr.Textbox(label="Enter your query here")
|
150 |
image = gr.Image(label="Upload your image")
|
151 |
-
#audio = gr.Audio(label="Upload or Record Audio")
|
152 |
-
#video = gr.Video(label="Upload or Record Video")
|
153 |
|
154 |
# Processing buttons
|
155 |
forward_button = gr.Button("Start CTM forward process")
|
|
|
2 |
import sys
|
3 |
|
4 |
import gradio as gr
|
5 |
+
|
6 |
+
sys.path.append("./ctm")
|
7 |
from ctm.ctms.ctm_base import BaseConsciousnessTuringMachine
|
8 |
|
9 |
ctm = BaseConsciousnessTuringMachine()
|
|
|
17 |
buffer = io.BytesIO()
|
18 |
image.save(buffer, format="PNG")
|
19 |
byte_data = buffer.getvalue()
|
20 |
+
base64_string = base64.b64encode(byte_data).decode("utf-8")
|
21 |
return base64_string
|
22 |
|
23 |
|
24 |
def introduction():
|
25 |
with gr.Column(scale=2):
|
26 |
+
gr.Image("images/CTM-AI.png", elem_id="banner-image", show_label=False)
|
|
|
|
|
27 |
with gr.Column(scale=5):
|
28 |
gr.Markdown(
|
29 |
"""Consciousness Turing Machine Demo
|
30 |
"""
|
31 |
)
|
32 |
|
33 |
+
|
34 |
def add_processor(processor_name, display_name, state):
|
35 |
+
print("add processor ", processor_name)
|
36 |
ctm.add_processor(processor_name)
|
37 |
print(ctm.processor_group_map)
|
38 |
print(len(ctm.processor_list))
|
39 |
+
return display_name + " (added)"
|
40 |
+
|
41 |
|
42 |
def processor_tab():
|
43 |
# Categorized model names
|
|
|
45 |
"gpt4_text_emotion_processor",
|
46 |
"gpt4_text_summary_processor",
|
47 |
"gpt4_speaker_intent_processor",
|
48 |
+
"roberta_text_sentiment_processor",
|
49 |
]
|
50 |
vision_processors = [
|
51 |
"gpt4v_cloth_fashion_processor",
|
52 |
"gpt4v_face_emotion_processor",
|
53 |
"gpt4v_ocr_processor",
|
54 |
"gpt4v_posture",
|
55 |
+
"gpt4v_scene_location_processor",
|
56 |
]
|
57 |
|
58 |
with gr.Blocks():
|
|
|
60 |
with gr.Column(scale=1):
|
61 |
gr.Markdown("### Text Processors")
|
62 |
for model_name in text_processors:
|
63 |
+
display_name = (
|
64 |
+
model_name.replace("processor", "")
|
65 |
+
.replace("_", " ")
|
66 |
+
.title()
|
67 |
+
)
|
68 |
|
69 |
button = gr.Button(display_name)
|
70 |
+
processor_name = gr.Textbox(
|
71 |
+
value=model_name, visible=False
|
72 |
+
)
|
73 |
+
display_name = gr.Textbox(
|
74 |
+
value=display_name, visible=False
|
75 |
+
)
|
76 |
button.click(
|
77 |
fn=add_processor,
|
78 |
inputs=[processor_name, display_name, gr.State()],
|
79 |
+
outputs=[button],
|
80 |
)
|
81 |
|
82 |
with gr.Column(scale=1):
|
83 |
gr.Markdown("### Vision Processors")
|
84 |
for model_name in vision_processors:
|
85 |
+
display_name = (
|
86 |
+
model_name.replace("processor", "")
|
87 |
+
.replace("_", " ")
|
88 |
+
.title()
|
89 |
+
)
|
90 |
|
91 |
button = gr.Button(display_name)
|
92 |
+
processor_name = gr.Textbox(
|
93 |
+
value=model_name, visible=False
|
94 |
+
)
|
95 |
+
display_name = gr.Textbox(
|
96 |
+
value=display_name, visible=False
|
97 |
+
)
|
98 |
button.click(
|
99 |
fn=add_processor,
|
100 |
inputs=[processor_name, display_name, gr.State()],
|
101 |
+
outputs=[button],
|
102 |
)
|
103 |
|
104 |
|
|
|
|
|
105 |
def forward(query, content, image, state):
|
106 |
+
state["question"] = query
|
107 |
+
ask_processors_output_info, state = ask_processors(
|
108 |
+
query, content, image, state
|
109 |
+
)
|
110 |
uptree_competition_output_info, state = uptree_competition(state)
|
111 |
ask_supervisor_output_info, state = ask_supervisor(state)
|
112 |
|
|
|
164 |
text = gr.Textbox(label="Enter your text here")
|
165 |
query = gr.Textbox(label="Enter your query here")
|
166 |
image = gr.Image(label="Upload your image")
|
167 |
+
# audio = gr.Audio(label="Upload or Record Audio")
|
168 |
+
# video = gr.Video(label="Upload or Record Video")
|
169 |
|
170 |
# Processing buttons
|
171 |
forward_button = gr.Button("Start CTM forward process")
|
ctm/ctms/ctm_base.py
CHANGED
@@ -207,7 +207,9 @@ class BaseConsciousnessTuringMachine(object):
|
|
207 |
audio_path=audio_path,
|
208 |
video_path=video_path,
|
209 |
)
|
210 |
-
import pdb
|
|
|
|
|
211 |
winning_output = self.uptree_competition(processor_output)
|
212 |
answer, score = self.ask_supervisor(question, winning_output)
|
213 |
if score > answer_threshold:
|
|
|
207 |
audio_path=audio_path,
|
208 |
video_path=video_path,
|
209 |
)
|
210 |
+
import pdb
|
211 |
+
|
212 |
+
pdb.set_trace()
|
213 |
winning_output = self.uptree_competition(processor_output)
|
214 |
answer, score = self.ask_supervisor(question, winning_output)
|
215 |
if score > answer_threshold:
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ scikit-learn==1.3.0
|
|
2 |
huggingface-hub==0.21.4
|
3 |
gradio==4.27.0
|
4 |
gradio_client==0.15.1
|
5 |
-
openai==1.23.3
|
|
|
|
2 |
huggingface-hub==0.21.4
|
3 |
gradio==4.27.0
|
4 |
gradio_client==0.15.1
|
5 |
+
openai==1.23.3
|
6 |
+
pre-commit==3.7.0
|