ppsingh commited on
Commit
4e66058
·
verified ·
1 Parent(s): 5a255f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -64
app.py CHANGED
@@ -146,81 +146,38 @@ def process_query(
146
  return final_state["result"]
147
 
148
  # Simple testing interface
149
- ui = gr.Interface(
150
- fn=process_query,
151
- inputs=gr.Textbox(lines=2, placeholder="Enter query here"),
152
- outputs="text",
153
- flagging_mode="never"
154
- )
155
-
156
- # Add a function to generate the graph visualization
157
- def get_graph_visualization():
158
- """Generate and return the LangGraph workflow visualization as a PIL Image."""
159
- # Generate the graph as PNG bytes
160
- graph_png_bytes = graph.get_graph().draw_mermaid_png()
161
-
162
- # Convert bytes to PIL Image for Gradio display
163
- graph_image = Image.open(io.BytesIO(graph_png_bytes))
164
- return graph_image
165
 
166
 
167
  # Guidance for ChatUI - can be removed later. Questionable whether front end even necessary. Maybe nice to show the graph.
168
  with gr.Blocks(title="ChatFed Orchestrator") as demo:
169
- gr.Markdown("# ChatFed Orchestrator")
170
- gr.Markdown("This LangGraph server exposes MCP endpoints for the ChatUI module to call (which triggers the graph).")
171
 
172
  with gr.Row():
173
  # Left column - Graph visualization
174
- with gr.Column(scale=1):
175
- gr.Markdown("**Workflow Visualization**")
176
- graph_display = gr.Image(
177
- value=get_graph_visualization(),
178
- label="LangGraph Workflow",
179
- interactive=False,
180
- height=300
181
  )
 
 
182
 
183
- # Add a refresh button for the graph
184
- refresh_graph_btn = gr.Button("🔄 Refresh Graph", size="sm")
185
- refresh_graph_btn.click(
186
- fn=get_graph_visualization,
187
- outputs=graph_display
188
- )
189
 
190
  # Right column - Interface and documentation
191
- with gr.Column(scale=2):
192
- gr.Markdown("**Available MCP Tools:**")
193
-
194
- with gr.Accordion("MCP Endpoint Information", open=True):
195
- gr.Markdown(f"""
196
- **MCP Server Endpoint:** https://giz-chatfed-orchestrator.hf.space/gradio_api/mcp/sse
197
-
198
- **For ChatUI Integration:**
199
- ```python
200
- from gradio_client import Client
201
-
202
- # Connect to orchestrator
203
- orchestrator_client = Client("https://giz-chatfed-orchestrator.hf.space")
204
-
205
- # Basic usage (no filters)
206
- response = orchestrator_client.predict(
207
- query="query",
208
- api_name="/process_query"
209
- )
210
-
211
- # Advanced usage with any combination of filters
212
- response = orchestrator_client.predict(
213
- query="query",
214
- reports_filter="annual_reports",
215
- sources_filter="internal",
216
- year_filter="2024",
217
- api_name="/process_query"
218
- )
219
- ```
220
- """)
221
-
222
- with gr.Accordion("Quick Testing Interface", open=True):
223
- ui.render()
224
 
225
  if __name__ == "__main__":
226
  demo.launch(
 
146
  return final_state["result"]
147
 
148
  # Simple testing interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
 
151
  # Guidance for ChatUI - can be removed later. Questionable whether front end even necessary. Maybe nice to show the graph.
152
  with gr.Blocks(title="ChatFed Orchestrator") as demo:
 
 
153
 
154
  with gr.Row():
155
  # Left column - Graph visualization
156
+ with gr.Column():
157
+ query_input = gr.Textbox(
158
+ label="query",
159
+ lines=2,
160
+ placeholder="Enter your search query here",
161
+ info="The query to search for in the vector database"
 
162
  )
163
+
164
+ submit_btn = gr.Button("Submit", variant="primary")
165
 
 
 
 
 
 
 
166
 
167
  # Right column - Interface and documentation
168
+ with gr.Column():
169
+ output = gr.Textbox(
170
+ label="answer",
171
+ lines=10,
172
+ show_copy_button=True
173
+ )
174
+
175
+ # UI event handler
176
+ submit_btn.click(
177
+ fn=retrieve,
178
+ inputs=[query_input, reports_input, sources_input, subtype_input, year_input],
179
+ outputs=output
180
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  if __name__ == "__main__":
183
  demo.launch(