leavoigt commited on
Commit
87b98d4
·
1 Parent(s): beae3a1

add geojson upload

Browse files
Files changed (2) hide show
  1. app.py +19 -31
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,36 +1,24 @@
1
  import gradio as gr
 
2
 
 
 
 
 
 
 
 
 
 
3
 
4
- def placeholder_function():
5
- print("hello!")
 
 
 
 
 
6
 
7
- ui = gr.Interface(
8
- fn=placeholder_function,
9
- inputs=[
10
- gr.Textbox(
11
- label="Query",
12
- lines=2,
13
- placeholder="Enter query here",
14
- info="The query to search for in the vector database"
15
- ),
16
- gr.Textbox(
17
- label="Context",
18
- lines=8,
19
- placeholder="Paste relevant context here",
20
- info="Provide the context/documents to use for answering. The API expects a list of dictionaries, but the UI should except anything"
21
- ),
22
- ],
23
- outputs=[gr.Text(label="Generated Answer", lines=6, show_copy_button=True)],
24
- title="ChatFed Generation Module",
25
- description="Ask questions based on provided context. Intended for use in RAG pipelines as an MCP server with other ChatFed modules (i.e. context supplied by semantic retriever service).",
26
- api_name="generate"
27
- )
28
 
29
- # Launch with MCP server enabled
30
- if __name__ == "__main__":
31
- ui.launch(
32
- server_name="0.0.0.0",
33
- server_port=7860,
34
- #mcp_server=True,
35
- show_error=True
36
- )
 
1
  import gradio as gr
2
+ import json
3
 
4
+ def process_geojson(file):
5
+ if file is None:
6
+ return {}
7
+
8
+ try:
9
+ with open(file, 'r', encoding='utf-8') as f:
10
+ return json.load(f)
11
+ except Exception as e:
12
+ return {"error": str(e)}
13
 
14
+ with gr.Blocks() as ui:
15
+ with gr.Row():
16
+ with gr.Column():
17
+ file_input = gr.File(file_types=[".geojson"])
18
+ submit_btn = gr.Button("Submit")
19
+ with gr.Column():
20
+ output = gr.JSON()
21
 
22
+ submit_btn.click(process_geojson, file_input, output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ ui.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1 +1,2 @@
1
- gradio==4.44.1
 
 
1
+ gradio==4.44.1
2
+ pydantic==2.10.6