Spaces:
Sleeping
Sleeping
Update ui/contentagentui.py
Browse files- ui/contentagentui.py +28 -25
ui/contentagentui.py
CHANGED
|
@@ -66,23 +66,32 @@ class ContentAgentUI:
|
|
| 66 |
# neutral; on_load will set real status and maybe auto-init
|
| 67 |
return "Checking endpoint status…"
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
if os.path.
|
| 75 |
-
for
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# ---------- agent call ----------
|
| 88 |
|
|
@@ -152,14 +161,8 @@ class ContentAgentUI:
|
|
| 152 |
|
| 153 |
|
| 154 |
# Examples (optional)
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
gr.Markdown("### Try one of these examples")
|
| 158 |
-
self.examples_radio = gr.Radio(choices=examples, label="Examples")
|
| 159 |
-
# fill the prompt when an example is picked
|
| 160 |
-
self.examples_radio.change(lambda ex: ex, inputs=self.examples_radio, outputs=self.prompt)
|
| 161 |
-
else:
|
| 162 |
-
gr.Markdown("*No examples found.*")
|
| 163 |
|
| 164 |
# Footer
|
| 165 |
gr.HTML("<div id='footer'>Thanks for trying it out!</div>")
|
|
|
|
| 66 |
# neutral; on_load will set real status and maybe auto-init
|
| 67 |
return "Checking endpoint status…"
|
| 68 |
|
| 69 |
+
|
| 70 |
+
def _get_example(self):
|
| 71 |
+
example_root = os.path.join(os.path.dirname(__file__), "examples")
|
| 72 |
+
examples = []
|
| 73 |
+
|
| 74 |
+
if os.path.exists(example_root):
|
| 75 |
+
example_files = [os.path.join(example_root, f) for f in os.listdir(example_root) if f.endswith(".txt")]
|
| 76 |
+
|
| 77 |
+
for file_path in example_files:
|
| 78 |
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
| 79 |
+
examples.append(f.read())
|
| 80 |
+
|
| 81 |
+
return examples
|
| 82 |
+
|
| 83 |
+
def _create_examples(self):
|
| 84 |
+
examples = self._get_example()
|
| 85 |
+
|
| 86 |
+
with self.ca_gui:
|
| 87 |
+
if examples:
|
| 88 |
+
example_radio = gr.Radio(choices=examples, label="Try one of these examples:")
|
| 89 |
+
# fill the prompt when an example is picked
|
| 90 |
+
example_radio.change(fn=lambda ex: ex, inputs=example_radio, outputs=self.user_input)
|
| 91 |
+
else:
|
| 92 |
+
gr.Markdown("*No examples found.*")
|
| 93 |
+
|
| 94 |
+
|
| 95 |
|
| 96 |
# ---------- agent call ----------
|
| 97 |
|
|
|
|
| 161 |
|
| 162 |
|
| 163 |
# Examples (optional)
|
| 164 |
+
self._create_examples()
|
| 165 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
# Footer
|
| 168 |
gr.HTML("<div id='footer'>Thanks for trying it out!</div>")
|