Spaces:
Runtime error
Runtime error
File size: 2,411 Bytes
fcb640f f4fcab8 fcb640f f4fcab8 fcb640f f4fcab8 fcb640f a8df29a fcb640f |
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 |
import gradio as gr
from medrax.agent import Agent
from medrax.tools import ChestXRayClassifierTool, ChestXRaySegmentationTool, XRayVQATool
from medrax.utils import load_prompts_from_file
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
# MedRAX ajanını başlatma fonksiyonu (main.py'den uyarlandı)
def initialize_agent(model="chatgpt-4o-latest", temperature=0.2):
# Sistem promptunu yükle
prompts = load_prompts_from_file("medrax/docs/system_prompts.txt")
prompt = prompts["MEDICAL_ASSISTANT"]
# Kullanılacak araçlar
tools_dict = {
"ChestXRayClassifierTool": ChestXRayClassifierTool(device="cuda"),
"ChestXRaySegmentationTool": ChestXRaySegmentationTool(device="cuda"),
"XRayVQATool": XRayVQATool(cache_dir="/model-weights", device="cuda"),
}
# Bellek ve model ayarları
checkpointer = MemorySaver()
model = ChatOpenAI(model=model, temperature=temperature)
# Ajanı başlat
agent = Agent(
model,
tools=list(tools_dict.values()),
log_tools=True,
log_dir="logs",
system_prompt=prompt,
checkpointer=checkpointer,
)
return agent
# Gradio arayüzü için analiz fonksiyonu
def analyze_xray(image, question):
# Ajanı başlat
agent = initialize_agent()
# Görüntüyü ve soruyu ajana ilet
# Not: Bu kısım MedRAX'in gerçek işleyişine bağlı olarak özelleştirilmeli
response = agent.run(f"Analyze this chest X-ray image and answer: {question}", image=image)
return response
# Gradio arayüzü
with gr.Blocks(title="MedRAX - Chest X-ray Analysis") as demo:
gr.Markdown("# MedRAX: Medical Reasoning Agent for Chest X-ray")
gr.Markdown("Upload a chest X-ray image and ask a question about it.")
with gr.Row():
with gr.Column():
image_input = gr.Image(type="pil", label="Upload Chest X-ray")
question_input = gr.Textbox(label="Your Question", placeholder="E.g., Is there a sign of pneumonia?")
submit_btn = gr.Button("Analyze")
with gr.Column():
output_text = gr.Textbox(label="Analysis Result", interactive=False)
# Butona tıklayınca analiz yap
submit_btn.click(
fn=analyze_xray,
inputs=[image_input, question_input],
outputs=output_text
)
# Uygulamayı başlat
demo.launch() |