Haofei Yu commited on
Commit
3a62692
1 Parent(s): dc7c3c1

Feature/support processor selection (#9)

Browse files

* support inner loop ctm

* support inner loop ctm (#8)

* change path

Files changed (3) hide show
  1. .github/workflows/sync.yml +1 -0
  2. .gitignore +1 -2
  3. app.py +53 -25
.github/workflows/sync.yml CHANGED
@@ -16,4 +16,5 @@ jobs:
16
  - name: Push to hub
17
  env:
18
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
 
19
  run: git push https://lwaekfjlk:$HF_TOKEN@huggingface.co/spaces/lwaekfjlk/ctm-space main --force
 
16
  - name: Push to hub
17
  env:
18
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_TOKEN }}
20
  run: git push https://lwaekfjlk:$HF_TOKEN@huggingface.co/spaces/lwaekfjlk/ctm-space main --force
.gitignore CHANGED
@@ -157,5 +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/
161
- **/ctm/*
 
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/
 
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import os
2
  import gradio as gr
 
 
3
  from ctm.ctms.ctm_base import BaseConsciousnessTuringMachine
4
 
5
  ctm = BaseConsciousnessTuringMachine()
@@ -20,33 +22,59 @@ def introduction():
20
  """
21
  )
22
 
23
- def add_processor(processor_name):
24
  print('add processor ', processor_name)
25
  ctm.add_processor(processor_name)
26
  print(len(ctm.processor_list))
 
27
 
28
  def processor_tab():
29
- with gr.Row() as row:
30
- button1 = gr.Button("Text Emotion Analyzer")
31
- button2 = gr.Button("Text Summary Generator")
32
-
33
- invisible_input1 = gr.Textbox(
34
- value="gpt4_text_emotion_processor",
35
- visible=False
36
- )
37
- invisible_input2 = gr.Textbox(
38
- value="gpt4_text_summary_processor",
39
- visible=False
40
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- button1.click(
43
- fn=add_processor,
44
- inputs=[invisible_input1],
45
- )
46
- button2.click(
47
- fn=add_processor,
48
- inputs=[invisible_input2],
49
- )
50
 
51
 
52
  def forward(query, content, image, state):
@@ -137,10 +165,10 @@ def interface_tab():
137
  def main():
138
  with gr.Blocks(
139
  css="""#chat_container {height: 820px; width: 1000px; margin-left: auto; margin-right: auto;}
140
- #chatbot {height: 600px; overflow: auto;}
141
- #create_container {height: 750px; margin-left: 0px; margin-right: 0px;}
142
- #tokenizer_renderer span {white-space: pre-wrap}
143
- """
144
  ) as demo:
145
  with gr.Row():
146
  introduction()
 
1
  import os
2
  import gradio as gr
3
+ import sys
4
+ sys.path.append('../CTM/')
5
  from ctm.ctms.ctm_base import BaseConsciousnessTuringMachine
6
 
7
  ctm = BaseConsciousnessTuringMachine()
 
22
  """
23
  )
24
 
25
+ def add_processor(processor_name, display_name, state):
26
  print('add processor ', processor_name)
27
  ctm.add_processor(processor_name)
28
  print(len(ctm.processor_list))
29
+ return display_name + ' (added)'
30
 
31
  def processor_tab():
32
+ # Categorized model names
33
+ text_processors = [
34
+ "gpt4_text_emotion_processor",
35
+ "gpt4_text_summary_processor",
36
+ "gpt4_speaker_intent_processor",
37
+ "roberta_text_sentiment_processor"
38
+ ]
39
+ vision_processors = [
40
+ "gpt4v_cloth_fashion_processor",
41
+ "gpt4v_face_emotion_processor",
42
+ "gpt4v_ocr_processor",
43
+ "gpt4v_posture",
44
+ "gpt4v_scene_location_processor"
45
+ ]
46
+
47
+ with gr.Blocks():
48
+ with gr.Row():
49
+ with gr.Column(scale=1):
50
+ gr.Markdown("### Text Processors")
51
+ for model_name in text_processors:
52
+ display_name = model_name.replace("processor", "").replace("_", " ").title()
53
+
54
+ button = gr.Button(display_name)
55
+ processor_name = gr.Textbox(value=model_name, visible=False)
56
+ display_name = gr.Textbox(value=display_name, visible=False)
57
+ button.click(
58
+ fn=add_processor,
59
+ inputs=[processor_name, display_name, gr.State()],
60
+ outputs=[button]
61
+ )
62
+
63
+ with gr.Column(scale=1):
64
+ gr.Markdown("### Vision Processors")
65
+ for model_name in vision_processors:
66
+ display_name = model_name.replace("processor", "").replace("_", " ").title()
67
+
68
+ button = gr.Button(display_name)
69
+ processor_name = gr.Textbox(value=model_name, visible=False)
70
+ display_name = gr.Textbox(value=display_name, visible=False)
71
+ button.click(
72
+ fn=add_processor,
73
+ inputs=[processor_name, display_name, gr.State()],
74
+ outputs=[button]
75
+ )
76
+
77
 
 
 
 
 
 
 
 
 
78
 
79
 
80
  def forward(query, content, image, state):
 
165
  def main():
166
  with gr.Blocks(
167
  css="""#chat_container {height: 820px; width: 1000px; margin-left: auto; margin-right: auto;}
168
+ #chatbot {height: 600px; overflow: auto;}
169
+ #create_container {height: 750px; margin-left: 0px; margin-right: 0px;}
170
+ #tokenizer_renderer span {white-space: pre-wrap}
171
+ """
172
  ) as demo:
173
  with gr.Row():
174
  introduction()