Spaces:
Running
Running
Show landing page when credentials not configured
Browse files- openmark/ui/app.py +76 -54
openmark/ui/app.py
CHANGED
|
@@ -120,63 +120,85 @@ def stats_fn():
|
|
| 120 |
# ββ Build UI ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 121 |
|
| 122 |
def build_ui():
|
| 123 |
-
categories = ["All"] + config.CATEGORIES
|
| 124 |
-
|
| 125 |
with gr.Blocks(title="OpenMark") as app:
|
| 126 |
gr.Markdown("# OpenMark β Your Personal Knowledge Graph")
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
with gr.
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
return app
|
| 182 |
|
|
|
|
| 120 |
# ββ Build UI ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 121 |
|
| 122 |
def build_ui():
|
|
|
|
|
|
|
| 123 |
with gr.Blocks(title="OpenMark") as app:
|
| 124 |
gr.Markdown("# OpenMark β Your Personal Knowledge Graph")
|
| 125 |
|
| 126 |
+
if _setup_error:
|
| 127 |
+
# No credentials β show landing page only
|
| 128 |
+
gr.Markdown(
|
| 129 |
+
"**8,000+ bookmarks, LinkedIn saves, and YouTube videos** indexed with "
|
| 130 |
+
"[pplx-embed](https://huggingface.co/collections/perplexity-ai/pplx-embed), "
|
| 131 |
+
"searchable with ChromaDB and Neo4j, queryable via a LangGraph agent.\n\n"
|
| 132 |
+
"Built by [Ahmad Othman Ammar Adi](https://github.com/OthmanAdi) Β· "
|
| 133 |
+
"[GitHub](https://github.com/OthmanAdi/OpenMark) Β· "
|
| 134 |
+
"[Dataset](https://huggingface.co/datasets/codingwithadi/openmark-bookmarks)\n\n"
|
| 135 |
+
"---\n\n"
|
| 136 |
+
"## Run it yourself\n\n"
|
| 137 |
+
"This Space requires your own data and credentials. "
|
| 138 |
+
"Clone the repo and follow the setup guide:\n\n"
|
| 139 |
+
"```bash\n"
|
| 140 |
+
"git clone https://github.com/OthmanAdi/OpenMark.git\n"
|
| 141 |
+
"cd OpenMark\n"
|
| 142 |
+
"pip install -r requirements.txt\n"
|
| 143 |
+
"cp .env.example .env # add your keys\n"
|
| 144 |
+
"python scripts/ingest.py\n"
|
| 145 |
+
"python openmark/ui/app.py\n"
|
| 146 |
+
"```"
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
categories = ["All"] + config.CATEGORIES
|
| 150 |
+
with gr.Tabs():
|
| 151 |
+
|
| 152 |
+
# Tab 1: Chat
|
| 153 |
+
with gr.Tab("Chat"):
|
| 154 |
+
thread = gr.Textbox(value="default", label="Session ID", scale=1)
|
| 155 |
+
chatbot = gr.Chatbot(height=500)
|
| 156 |
+
msg_box = gr.Textbox(
|
| 157 |
+
placeholder="Ask anything about your saved bookmarks...",
|
| 158 |
+
label="Message", lines=2,
|
| 159 |
+
)
|
| 160 |
+
send_btn = gr.Button("Send", variant="primary")
|
| 161 |
+
|
| 162 |
+
send_btn.click(
|
| 163 |
+
chat_fn,
|
| 164 |
+
inputs=[msg_box, chatbot, thread],
|
| 165 |
+
outputs=[chatbot, msg_box],
|
| 166 |
+
)
|
| 167 |
+
msg_box.submit(
|
| 168 |
+
chat_fn,
|
| 169 |
+
inputs=[msg_box, chatbot, thread],
|
| 170 |
+
outputs=[chatbot, msg_box],
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
# Tab 2: Search
|
| 174 |
+
with gr.Tab("Search"):
|
| 175 |
+
with gr.Row():
|
| 176 |
+
q_input = gr.Textbox(placeholder="Search your knowledge base...", label="Query", scale=3)
|
| 177 |
+
cat_input = gr.Dropdown(categories, value="All", label="Category")
|
| 178 |
+
with gr.Row():
|
| 179 |
+
score_input = gr.Slider(0, 10, value=0, step=1, label="Min Quality Score")
|
| 180 |
+
n_input = gr.Slider(5, 50, value=10, step=5, label="Results")
|
| 181 |
+
search_btn = gr.Button("Search", variant="primary")
|
| 182 |
+
search_output = gr.Markdown()
|
| 183 |
+
|
| 184 |
+
search_btn.click(
|
| 185 |
+
search_fn,
|
| 186 |
+
inputs=[q_input, cat_input, score_input, n_input],
|
| 187 |
+
outputs=search_output,
|
| 188 |
+
)
|
| 189 |
+
q_input.submit(
|
| 190 |
+
search_fn,
|
| 191 |
+
inputs=[q_input, cat_input, score_input, n_input],
|
| 192 |
+
outputs=search_output,
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# Tab 3: Stats
|
| 196 |
+
with gr.Tab("Stats"):
|
| 197 |
+
refresh_btn = gr.Button("Refresh Stats")
|
| 198 |
+
stats_output = gr.Markdown()
|
| 199 |
+
|
| 200 |
+
refresh_btn.click(stats_fn, outputs=stats_output)
|
| 201 |
+
app.load(stats_fn, outputs=stats_output)
|
| 202 |
|
| 203 |
return app
|
| 204 |
|