yetessam commited on
Commit
75717e1
·
verified ·
1 Parent(s): fc77fc0

Update ui/contentagentui.py

Browse files
Files changed (1) hide show
  1. 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
- def _load_examples(self) -> list[str]:
70
-
71
- print("load examples")
72
- ex_dir = os.path.join(os.path.dirname(__file__), "examples")
73
- out: list[str] = []
74
- if os.path.isdir(ex_dir):
75
- for name in sorted(os.listdir(ex_dir)):
76
- if name.lower().endswith(".txt"):
77
- p = os.path.join(ex_dir, name)
78
-
79
- print(p)
80
- try:
81
- with open(p, "r", encoding="utf-8", errors="ignore") as f:
82
- out.append(f.read())
83
- except Exception:
84
- pass
85
- return out
 
 
 
 
 
 
 
 
 
86
 
87
  # ---------- agent call ----------
88
 
@@ -152,14 +161,8 @@ class ContentAgentUI:
152
 
153
 
154
  # Examples (optional)
155
- examples = self._load_examples()
156
- if examples:
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>")