File size: 2,647 Bytes
2f22a2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
import sys
import subprocess
import time

# Başlangıç kurulumu
def setup_environment():
    # Repo klonlama (eğer yoksa)
    if not os.path.exists('MedRAX'):
        print("MedRAX reposunu klonlama...")
        os.system('git clone https://github.com/bowang-lab/MedRAX.git')
        
        # Repoyu kurma
        print("MedRAX'ı kurma...")
        os.system('cd MedRAX && pip install -e .')
        
        # ChestAgentBench veri setini indirme
        print("ChestAgentBench veri setini indirme...")
        os.system('huggingface-cli download wanglab/chestagentbench --repo-type dataset --local-dir chestagentbench')
        
        print("Kurulum tamamlandı!")
    return "Kurulum tamamlandı!"

# MedRAX çalıştırma fonksiyonu
def run_medrax():
    try:
        # MedRAX ana dizinine git ve çalıştır
        result = subprocess.run(
            ['cd MedRAX && python main.py'], 
            shell=True, 
            capture_output=True, 
            text=True
        )
        return f"MedRAX çıktısı:\n{result.stdout}\n\nHatalar:\n{result.stderr}"
    except Exception as e:
        return f"Hata oluştu: {str(e)}"

# Gradio arayüzü
with gr.Blocks() as demo:
    gr.Markdown("# MedRAX Demo")
    
    with gr.Tab("Kurulum"):
        setup_button = gr.Button("Ortamı Hazırla")
        setup_output = gr.Textbox(label="Kurulum Çıktısı")
        setup_button.click(fn=setup_environment, outputs=setup_output)
    
    with gr.Tab("MedRAX Çalıştır"):
        run_button = gr.Button("MedRAX'ı Çalıştır")
        run_output = gr.Textbox(label="Çalıştırma Çıktısı")
        run_button.click(fn=run_medrax, outputs=run_output)
        
    with gr.Tab("Manuel Girdi"):
        cmd_input = gr.Textbox(label="Manuel Komut (örn: cd MedRAX && python custom_script.py)", value="cd MedRAX && python main.py")
        cmd_button = gr.Button("Komutu Çalıştır")
        cmd_output = gr.Textbox(label="Komut Çıktısı")
        
        def run_command(command):
            try:
                result = subprocess.run(command, shell=True, capture_output=True, text=True)
                return f"Çıktı:\n{result.stdout}\n\nHatalar:\n{result.stderr}"
            except Exception as e:
                return f"Hata: {str(e)}"
        
        cmd_button.click(fn=run_command, inputs=cmd_input, outputs=cmd_output)

# Demo başlatma
if __name__ == "__main__":
    # Başlangıçta ortamı hazırla
    if not os.path.exists('MedRAX'):
        print("İlk çalıştırma: Ortam hazırlanıyor...")
        setup_environment()
    
    # Arayüzü başlat
    demo.launch()