Spaces:
Paused
Paused
tmzh
commited on
Commit
·
d2a7e23
1
Parent(s):
ef8dd8b
refactoring
Browse files
app.py
CHANGED
|
@@ -148,35 +148,37 @@ def generate_clue_callback(group: List[str]) -> gr.update:
|
|
| 148 |
clue = generate_clue(group)
|
| 149 |
return gr.update(value=clue['clue'], info=clue['explanation'])
|
| 150 |
|
| 151 |
-
# UI Setup
|
| 152 |
-
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 153 |
-
gr.Markdown("# *Codenames* Clue Generator")
|
| 154 |
-
gr.Markdown("Provide a list of words to generate clues")
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
group_inputs, clue_buttons, clue_outputs = [], [], []
|
| 165 |
|
| 166 |
-
for i in range(4):
|
| 167 |
with gr.Row():
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
|
| 182 |
-
demo.launch(share=True, debug=True)
|
|
|
|
| 148 |
clue = generate_clue(group)
|
| 149 |
return gr.update(value=clue['clue'], info=clue['explanation'])
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
if __name__ == "__main__":
|
| 153 |
+
# UI Setup
|
| 154 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 155 |
+
gr.Markdown("# *Codenames* Clue Generator")
|
| 156 |
+
gr.Markdown("Provide a list of words to generate clues")
|
| 157 |
|
| 158 |
+
with gr.Row():
|
| 159 |
+
game_image = gr.Image(type="pil")
|
| 160 |
+
word_list_input = gr.Dropdown(label="Detected words", choices=[], multiselect=True, interactive=True)
|
|
|
|
|
|
|
| 161 |
|
|
|
|
| 162 |
with gr.Row():
|
| 163 |
+
detect_words_button = gr.Button("Detect Words")
|
| 164 |
+
group_words_button = gr.Button("Group Words")
|
| 165 |
+
|
| 166 |
+
group_inputs, clue_buttons, clue_outputs = [], [], []
|
| 167 |
+
|
| 168 |
+
for i in range(4):
|
| 169 |
+
with gr.Row():
|
| 170 |
+
group_input = gr.Dropdown(label=f"Group {i + 1}", choices=[], allow_custom_value=True, multiselect=True, interactive=True)
|
| 171 |
+
clue_button = gr.Button("Generate Clue", size='sm')
|
| 172 |
+
clue_output = gr.Textbox(label=f"Clue {i + 1}")
|
| 173 |
+
group_inputs.append(group_input)
|
| 174 |
+
clue_buttons.append(clue_button)
|
| 175 |
+
clue_outputs.append(clue_output)
|
| 176 |
|
| 177 |
+
# Event handlers
|
| 178 |
+
detect_words_button.click(fn=process_image, inputs=game_image, outputs=[word_list_input])
|
| 179 |
+
group_words_button.click(fn=group_words_callback, inputs=word_list_input, outputs=group_inputs)
|
| 180 |
|
| 181 |
+
for i in range(4):
|
| 182 |
+
clue_buttons[i].click(generate_clue_callback, inputs=group_inputs[i], outputs=clue_outputs[i])
|
| 183 |
|
| 184 |
+
demo.launch(share=True, debug=True)
|