spoon-1 commited on
Commit
694c23d
·
verified ·
1 Parent(s): 548fb4e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from google import genai
3
+ import pandas as pd
4
+
5
+ def fetch_gemini_models(api_key):
6
+ """
7
+ Fetches available Gemini models and returns them as a pandas DataFrame.
8
+ """
9
+ if not api_key:
10
+ return None, "Error: GEMINI_API_KEY is required."
11
+
12
+ try:
13
+ client = genai.Client(api_key=api_key)
14
+ models = list(client.models.list())
15
+ models.sort(key=lambda x: x.name)
16
+
17
+ # Mapping for Japanese translation
18
+ method_translation = {
19
+ "generateContent": "コンテンツ生成",
20
+ "countTokens": "トークン計算",
21
+ "createCachedContent": "キャッシュ作成",
22
+ "embedText": "テキスト埋め込み",
23
+ "batchGenerate": "バッチ生成",
24
+ "embedContent": "コンテンツ埋め込み"
25
+ }
26
+
27
+ data = []
28
+ for m in models:
29
+ if hasattr(m, "supported_actions") and m.supported_actions and "generateContent" in m.supported_actions:
30
+ translated_methods = [method_translation.get(method, method) for method in m.supported_actions]
31
+ methods = ", ".join(translated_methods)
32
+
33
+ data.append({
34
+ "Model Name": m.name,
35
+ "Display Name": m.display_name,
36
+ "Supported Methods (JP)": methods
37
+ })
38
+
39
+ if not data:
40
+ return None, "No models found that support 'generateContent'."
41
+
42
+ df = pd.DataFrame(data)
43
+ return df, "Success: Models fetched successfully."
44
+
45
+ except Exception as e:
46
+ return None, f"An error occurred: {str(e)}"
47
+
48
+ # Define Gradio Theme (Rich Aesthetics)
49
+ theme = gr.themes.Soft(
50
+ primary_hue="indigo",
51
+ secondary_hue="blue",
52
+ neutral_hue="slate",
53
+ ).set(
54
+ button_primary_background_fill='*primary_600',
55
+ button_primary_background_fill_hover='*primary_700',
56
+ )
57
+
58
+ with gr.Blocks(theme=theme, title="Gemini Model Checker") as demo:
59
+ gr.Markdown(
60
+ """
61
+ # 💎 Gemini Model Checker
62
+ Hugging Face Spaces上のGradioで、利用可能なGeminiモデルを簡単に確認できます。
63
+ """
64
+ )
65
+
66
+ with gr.Row():
67
+ api_key_input = gr.Textbox(
68
+ label="Gemini API Key",
69
+ placeholder="AIzaSy...",
70
+ type="password",
71
+ interactive=True,
72
+ scale=4
73
+ )
74
+ fetch_btn = gr.Button("Fetch Models", variant="primary", scale=1)
75
+
76
+ output_status = gr.Textbox(label="Status", interactive=False)
77
+ output_table = gr.DataFrame(label="Available Models")
78
+
79
+ fetch_btn.click(
80
+ fn=fetch_gemini_models,
81
+ inputs=api_key_input,
82
+ outputs=[output_table, output_status]
83
+ )
84
+
85
+ gr.Markdown(
86
+ """
87
+ ---
88
+ ### 使い方
89
+ 1. Google AI Studioから取得した **APIキー** を入力します。
90
+ 2. **Fetch Models** ボタンをクリックします。
91
+ 3. 利用可能なモデルの一覧が表示されます。
92
+ """
93
+ )
94
+
95
+ if __name__ == "__main__":
96
+ demo.launch()