Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
import subprocess
|
5 |
+
import time
|
6 |
+
|
7 |
+
# Başlangıç kurulumu
|
8 |
+
def setup_environment():
|
9 |
+
# Repo klonlama (eğer yoksa)
|
10 |
+
if not os.path.exists('MedRAX'):
|
11 |
+
print("MedRAX reposunu klonlama...")
|
12 |
+
os.system('git clone https://github.com/bowang-lab/MedRAX.git')
|
13 |
+
|
14 |
+
# Repoyu kurma
|
15 |
+
print("MedRAX'ı kurma...")
|
16 |
+
os.system('cd MedRAX && pip install -e .')
|
17 |
+
|
18 |
+
# ChestAgentBench veri setini indirme
|
19 |
+
print("ChestAgentBench veri setini indirme...")
|
20 |
+
os.system('huggingface-cli download wanglab/chestagentbench --repo-type dataset --local-dir chestagentbench')
|
21 |
+
|
22 |
+
print("Kurulum tamamlandı!")
|
23 |
+
return "Kurulum tamamlandı!"
|
24 |
+
|
25 |
+
# MedRAX çalıştırma fonksiyonu
|
26 |
+
def run_medrax():
|
27 |
+
try:
|
28 |
+
# MedRAX ana dizinine git ve çalıştır
|
29 |
+
result = subprocess.run(
|
30 |
+
['cd MedRAX && python main.py'],
|
31 |
+
shell=True,
|
32 |
+
capture_output=True,
|
33 |
+
text=True
|
34 |
+
)
|
35 |
+
return f"MedRAX çıktısı:\n{result.stdout}\n\nHatalar:\n{result.stderr}"
|
36 |
+
except Exception as e:
|
37 |
+
return f"Hata oluştu: {str(e)}"
|
38 |
+
|
39 |
+
# Gradio arayüzü
|
40 |
+
with gr.Blocks() as demo:
|
41 |
+
gr.Markdown("# MedRAX Demo")
|
42 |
+
|
43 |
+
with gr.Tab("Kurulum"):
|
44 |
+
setup_button = gr.Button("Ortamı Hazırla")
|
45 |
+
setup_output = gr.Textbox(label="Kurulum Çıktısı")
|
46 |
+
setup_button.click(fn=setup_environment, outputs=setup_output)
|
47 |
+
|
48 |
+
with gr.Tab("MedRAX Çalıştır"):
|
49 |
+
run_button = gr.Button("MedRAX'ı Çalıştır")
|
50 |
+
run_output = gr.Textbox(label="Çalıştırma Çıktısı")
|
51 |
+
run_button.click(fn=run_medrax, outputs=run_output)
|
52 |
+
|
53 |
+
with gr.Tab("Manuel Girdi"):
|
54 |
+
cmd_input = gr.Textbox(label="Manuel Komut (örn: cd MedRAX && python custom_script.py)", value="cd MedRAX && python main.py")
|
55 |
+
cmd_button = gr.Button("Komutu Çalıştır")
|
56 |
+
cmd_output = gr.Textbox(label="Komut Çıktısı")
|
57 |
+
|
58 |
+
def run_command(command):
|
59 |
+
try:
|
60 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
61 |
+
return f"Çıktı:\n{result.stdout}\n\nHatalar:\n{result.stderr}"
|
62 |
+
except Exception as e:
|
63 |
+
return f"Hata: {str(e)}"
|
64 |
+
|
65 |
+
cmd_button.click(fn=run_command, inputs=cmd_input, outputs=cmd_output)
|
66 |
+
|
67 |
+
# Demo başlatma
|
68 |
+
if __name__ == "__main__":
|
69 |
+
# Başlangıçta ortamı hazırla
|
70 |
+
if not os.path.exists('MedRAX'):
|
71 |
+
print("İlk çalıştırma: Ortam hazırlanıyor...")
|
72 |
+
setup_environment()
|
73 |
+
|
74 |
+
# Arayüzü başlat
|
75 |
+
demo.launch()
|