matsuap commited on
Commit
0baa4be
·
1 Parent(s): 04ea0e7

Update .gitignore to include .env, modify app.py to load API key from environment variables, and update requirements.txt to add requests and python-dotenv.

Browse files
Files changed (3) hide show
  1. .gitignore +2 -1
  2. app.py +10 -4
  3. requirements.txt +3 -0
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  .venv/
2
- *.un~
 
 
1
  .venv/
2
+ *.un~
3
+ .env
app.py CHANGED
@@ -1,7 +1,14 @@
1
  import gradio as gr
2
  import requests
 
 
3
 
4
- def brave_search(query, api_key):
 
 
 
 
 
5
  url = "https://api.search.brave.com/res/v1/web/search"
6
  headers = {
7
  "Accept": "application/json",
@@ -25,11 +32,10 @@ def brave_search(query, api_key):
25
 
26
  with gr.Blocks() as demo:
27
  gr.Markdown("# Brave API 検索アプリ")
28
- api_key = gr.Textbox(label="Brave APIキー", type="password")
29
  query = gr.Textbox(label="検索クエリ")
30
  output = gr.Textbox(label="検索結果", lines=10)
31
  search_btn = gr.Button("検索")
32
- search_btn.click(fn=brave_search, inputs=[query, api_key], outputs=output)
33
 
34
  if __name__ == "__main__":
35
- demo.launch(mcp_server=True)
 
1
  import gradio as gr
2
  import requests
3
+ import os
4
+ from dotenv import load_dotenv
5
 
6
+ load_dotenv()
7
+
8
+ def brave_search(query):
9
+ api_key = os.getenv("BRAVE_API_KEY")
10
+ if not api_key:
11
+ return "Brave APIキーが環境変数に設定されていません。"
12
  url = "https://api.search.brave.com/res/v1/web/search"
13
  headers = {
14
  "Accept": "application/json",
 
32
 
33
  with gr.Blocks() as demo:
34
  gr.Markdown("# Brave API 検索アプリ")
 
35
  query = gr.Textbox(label="検索クエリ")
36
  output = gr.Textbox(label="検索結果", lines=10)
37
  search_btn = gr.Button("検索")
38
+ search_btn.click(fn=brave_search, inputs=[query], outputs=output)
39
 
40
  if __name__ == "__main__":
41
+ demo.launch(mcp_server=Tre)
requirements.txt CHANGED
@@ -1,2 +1,5 @@
1
  gradio[mcp]
2
  numpy
 
 
 
 
1
  gradio[mcp]
2
  numpy
3
+ requests
4
+ python-dotenv
5
+ mcp