File size: 2,523 Bytes
9791162
71dda67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9791162
 
 
 
 
 
 
 
 
71dda67
 
9791162
 
71dda67
 
9791162
71dda67
 
 
 
 
 
 
 
 
 
 
 
 
 
9791162
 
71dda67
 
 
 
 
9791162
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import gradio as gr
import os
import requests
from tqdm import tqdm

def check_and_download_model():
    temp_dir = "/tmp"
    model_path = os.path.join(temp_dir, "large-v2.pt")
    
    if os.path.exists(model_path):
        return f"モデルは既に存在します: {model_path}"
    
    url = "https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt"
    
    try:
        response = requests.get(url, stream=True)
        response.raise_for_status()
        total_size = int(response.headers.get('content-length', 0))
        
        with open(model_path, 'wb') as f, tqdm(
            desc=model_path,
            total=total_size,
            unit='iB',
            unit_scale=True,
            unit_divisor=1024,
        ) as pbar:
            for data in response.iter_content(chunk_size=1024):
                size = f.write(data)
                pbar.update(size)
                
        return f"モデルのダウンロードが完了しました: {model_path}"
        
    except Exception as e:
        return f"エラーが発生しました: {e}"

def click_test():
    """1から10までのランダムな数値を生成する関数"""
    import random
    number = random.randint(1, 10)
    return f"生成された数値: {number}"

# Gradio インターフェースの作成
with gr.Blocks() as demo:
    gr.Markdown("# Whisper モデルチェッカー & ランダム数値ジェネレーター")
    gr.Markdown("下のボタンでモデルの確認・ダウンロードと、ランダム数値の生成ができます。")
    
    # 結果表示用のテキストボックス
    model_status = gr.Text(label="モデルの状態")
    output_text = gr.Text(label="ランダム数値の結果")
    
    with gr.Row():
        # モデルチェック用ボタン
        check_btn = gr.Button(
            value="モデルを確認する",
            variant="secondary",
            size="lg"
        )
        
        # ランダム数値生成用ボタン
        generate_btn = gr.Button(
            value="数値を生成する",
            variant="primary",
            size="lg"
        )
    
    # ボタンクリック時のイベント設定
    check_btn.click(
        fn=check_and_download_model,
        outputs=model_status
    )
    
    generate_btn.click(
        fn=click_test,
        outputs=output_text
    )

# アプリケーションの起動
if __name__ == "__main__":
    demo.launch()