mgokg commited on
Commit
2bfd637
·
verified ·
1 Parent(s): 70394eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -3,6 +3,11 @@ import requests
3
  from datetime import datetime, timedelta
4
  import xml.etree.ElementTree as ET
5
  import json
 
 
 
 
 
6
 
7
  def get_station_info(pattern, client_id, api_key):
8
  """Ermittelt EVA-Nummer und offiziellen Namen."""
@@ -103,18 +108,17 @@ def search_next_3_connections(departure, destination, client_id, api_key):
103
 
104
  # --- Gradio UI ---
105
 
106
- def ui_wrapper(dep, dest, cid, akey):
107
- results = search_next_3_connections(dep, dest, cid, akey)
 
 
 
108
  return json.dumps(results, indent=4, ensure_ascii=False)
109
 
110
  with gr.Blocks(title="DB JSON Fahrplan", theme=gr.themes.Soft()) as demo:
111
  gr.Markdown("# 🚆 DB Verbindungs-Suche (JSON)")
112
  gr.Markdown("Ermittelt die nächsten 3 Verbindungen ab dem aktuellen Zeitstempel.")
113
 
114
- with gr.Row():
115
- cid_input = gr.Textbox(label="DB Client ID", type="password")
116
- akey_input = gr.Textbox(label="DB API Key", type="password")
117
-
118
  with gr.Row():
119
  dep_input = gr.Textbox(label="Abfahrtsort", placeholder="z.B. Berlin")
120
  dest_input = gr.Textbox(label="Zielort", placeholder="z.B. Hamburg")
@@ -122,7 +126,7 @@ with gr.Blocks(title="DB JSON Fahrplan", theme=gr.themes.Soft()) as demo:
122
  btn = gr.Button("Suchen", variant="primary")
123
  output = gr.JSON(label="JSON Ergebnis") # Nutzt Gradio JSON Komponente für schöneres Format
124
 
125
- btn.click(fn=ui_wrapper, inputs=[dep_input, dest_input, cid_input, akey_input], outputs=output)
126
 
127
  if __name__ == "__main__":
128
- demo.launch()
 
3
  from datetime import datetime, timedelta
4
  import xml.etree.ElementTree as ET
5
  import json
6
+ import os
7
+
8
+ # Load credentials from environment variables
9
+ CLIENT_ID = os.environ.get('client_id')
10
+ API_KEY = os.environ.get('api_key')
11
 
12
  def get_station_info(pattern, client_id, api_key):
13
  """Ermittelt EVA-Nummer und offiziellen Namen."""
 
108
 
109
  # --- Gradio UI ---
110
 
111
+ def ui_wrapper(dep, dest):
112
+ if not CLIENT_ID or not API_KEY:
113
+ return {"error": "API credentials not configured. Please set client_id and api_key as environment variables."}
114
+
115
+ results = search_next_3_connections(dep, dest, CLIENT_ID, API_KEY)
116
  return json.dumps(results, indent=4, ensure_ascii=False)
117
 
118
  with gr.Blocks(title="DB JSON Fahrplan", theme=gr.themes.Soft()) as demo:
119
  gr.Markdown("# 🚆 DB Verbindungs-Suche (JSON)")
120
  gr.Markdown("Ermittelt die nächsten 3 Verbindungen ab dem aktuellen Zeitstempel.")
121
 
 
 
 
 
122
  with gr.Row():
123
  dep_input = gr.Textbox(label="Abfahrtsort", placeholder="z.B. Berlin")
124
  dest_input = gr.Textbox(label="Zielort", placeholder="z.B. Hamburg")
 
126
  btn = gr.Button("Suchen", variant="primary")
127
  output = gr.JSON(label="JSON Ergebnis") # Nutzt Gradio JSON Komponente für schöneres Format
128
 
129
+ btn.click(fn=ui_wrapper, inputs=[dep_input, dest_input], outputs=output)
130
 
131
  if __name__ == "__main__":
132
+ demo.launch(mcp_server=True)