crcdng commited on
Commit
bd08da1
·
1 Parent(s): f16c022

test api key on hf

Browse files
Files changed (4) hide show
  1. README.md +4 -2
  2. app.py +6 -6
  3. doomsweek_mcp_server copy.py +0 -74
  4. doomsweek_mcp_server.py +1 -1
README.md CHANGED
@@ -7,7 +7,9 @@ sdk: gradio
7
  sdk_version: 5.32.1
8
  app_file: app.py
9
  pinned: false
10
- short_description: Can we survive the next 7 days?
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
7
  sdk_version: 5.32.1
8
  app_file: app.py
9
  pinned: false
10
+ tags:
11
+ - Agents-MCP-Hackathon
12
+ - agent-demo-track
13
+ short_description: Can humanity survive the next 7 days?
14
  ---
15
 
 
app.py CHANGED
@@ -55,7 +55,7 @@ class MCPClientWrapper:
55
  } for tool in response.tools]
56
 
57
  tool_names = [tool["name"] for tool in self.tools]
58
- return f"Connected to MCP server. Available tools: {', '.join(tool_names)}"
59
 
60
  def process_message(self, message: str, history: List[Union[Dict[str, Any], ChatMessage]]) -> tuple:
61
  if not self.session:
@@ -194,17 +194,17 @@ client = MCPClientWrapper()
194
  def gradio_interface():
195
  with gr.Blocks(title="MCP Doomsweek Client") as demo:
196
  gr.Markdown("# MCP Doomsweek Assistant")
197
- gr.Markdown("Connect to your MCP Doomsweek Server and chat with the assistant")
198
 
199
  with gr.Row(equal_height=True):
200
  with gr.Column(scale=4):
201
  server_path = gr.Textbox(
202
  label="Server Script Path",
203
- placeholder="Enter path to server script (e.g., weather.py)",
204
  value="doomsweek_mcp_server.py"
205
  )
206
  with gr.Column(scale=1):
207
- connect_btn = gr.Button("Connect")
208
 
209
  status = gr.Textbox(label="Connection Status", interactive=False)
210
 
@@ -218,8 +218,8 @@ def gradio_interface():
218
 
219
  with gr.Row(equal_height=True):
220
  msg = gr.Textbox(
221
- label="Your Question",
222
- placeholder="Ask about weather or alerts (e.g., What's the weather in New York?)",
223
  scale=4
224
  )
225
  clear_btn = gr.Button("Clear Chat", scale=1)
 
55
  } for tool in response.tools]
56
 
57
  tool_names = [tool["name"] for tool in self.tools]
58
+ return f"Connected to DOOMSWEEK MCP server. Available tools: {', '.join(tool_names)}"
59
 
60
  def process_message(self, message: str, history: List[Union[Dict[str, Any], ChatMessage]]) -> tuple:
61
  if not self.session:
 
194
  def gradio_interface():
195
  with gr.Blocks(title="MCP Doomsweek Client") as demo:
196
  gr.Markdown("# MCP Doomsweek Assistant")
197
+ gr.Markdown("Connect to the DOOMSWEEK MCP Server and chat with the assistant")
198
 
199
  with gr.Row(equal_height=True):
200
  with gr.Column(scale=4):
201
  server_path = gr.Textbox(
202
  label="Server Script Path",
203
+ placeholder="Enter path to server script (e.g., doomsweek_mcp_server.py)",
204
  value="doomsweek_mcp_server.py"
205
  )
206
  with gr.Column(scale=1):
207
+ connect_btn = gr.Button("Connect", variant='secondary')
208
 
209
  status = gr.Textbox(label="Connection Status", interactive=False)
210
 
 
218
 
219
  with gr.Row(equal_height=True):
220
  msg = gr.Textbox(
221
+ label="Your Question about Humaiity's Fate",
222
+ placeholder="Ask (e.g., 'How likely is it that humanity will survive the next week?')",
223
  scale=4
224
  )
225
  clear_btn = gr.Button("Clear Chat", scale=1)
doomsweek_mcp_server copy.py DELETED
@@ -1,74 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- import gradio as gr
4
- import json
5
- import os
6
- import re
7
- import requests
8
-
9
-
10
-
11
- def calc_asteroid_factor(data, weight=1.0):
12
- """
13
- Calculates the asteroid doom probability.
14
-
15
- Args:
16
- data (object): The data structure returned from NASA
17
- weight (float): The weight to apply to the hazard factor.
18
-
19
- Returns:
20
- Weighted factor for Near Earth Object impact for the next seven days.
21
- """
22
-
23
- objects = [obj for sublist in data["near_earth_objects"].values() for obj in sublist]
24
-
25
- num_objects = len(objects)
26
-
27
- hazardous_objects = [obj for sublist in data["near_earth_objects"].values() for obj in sublist if obj["is_potentially_hazardous_asteroid"] == True]
28
-
29
- num_hazardous_objects = len(hazardous_objects)
30
-
31
- return (num_hazardous_objects/num_objects * weight) # hazard factor
32
-
33
-
34
- def fetch_asteroid_data(url, api_key):
35
- """
36
- Fetches data from the NASA Near Earth Object Web Service.
37
-
38
- Returns:
39
- Near Earth Objects for the next seven days.
40
- """
41
-
42
- request_data = requests.get(
43
- url,
44
- params={"api_key": api_key},
45
- )
46
-
47
- if request_data.status_code != 200:
48
- return None
49
- else:
50
- return json.loads(request_data.content)
51
-
52
-
53
- def calc_doom_probability():
54
- """
55
- Calculates the overall doom probability.
56
-
57
- Returns:
58
- The overall doom probability for the next seven days.
59
- """
60
-
61
- nasa_url = "https://api.nasa.gov/neo/rest/v1/feed"
62
- nasa_api_key = os.getenv("NASA_API_KEY")
63
-
64
- if not nasa_api_key:
65
- return "ERROR: NASA_API_KEY not set."
66
- else:
67
- nasa_data = fetch_asteroid_data(nasa_url, nasa_api_key)
68
- if not nasa_data:
69
- return "ERROR: Unable to fetch data from NASA API."
70
- else:
71
- return calc_asteroid_factor(nasa_data, weight=1.0)
72
-
73
- demo = gr.Interface(fn=calc_doom_probability, inputs=None, outputs="text")
74
- demo.launch(mcp_server=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
doomsweek_mcp_server.py CHANGED
@@ -82,6 +82,6 @@ async def calc_doom_probability():
82
  # demo.launch(mcp_server=True)
83
 
84
  if __name__ == "__main__":
85
- load_dotenv()
86
  print(os.getenv("NASA_API_KEY"))
87
  mcp.run(transport='stdio')
 
82
  # demo.launch(mcp_server=True)
83
 
84
  if __name__ == "__main__":
85
+ # load_dotenv()
86
  print(os.getenv("NASA_API_KEY"))
87
  mcp.run(transport='stdio')