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()