|
|
import gradio as gr
|
|
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
import torch
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
model_name = "AventIQ-AI/distilbert-disease-specialist-recommendation"
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
model = model.to(device)
|
|
|
|
|
|
|
|
|
labels = ["Cardiology", "Neurology", "Orthopedics", "Dermatology"]
|
|
|
|
|
|
|
|
|
def recommend_specialist(symptoms):
|
|
|
inputs = tokenizer(symptoms, return_tensors="pt", padding=True, truncation=True, max_length=512).to(device)
|
|
|
outputs = model(**inputs)
|
|
|
probabilities = torch.nn.functional.softmax(outputs.logits, dim=1)[0]
|
|
|
confidence, predicted_class = torch.max(probabilities, dim=0)
|
|
|
recommended_specialist = labels[predicted_class]
|
|
|
return f"Recommended Specialist: {recommended_specialist} (Confidence: {confidence.item():.2f})"
|
|
|
|
|
|
|
|
|
iface = gr.Interface(
|
|
|
fn=recommend_specialist,
|
|
|
inputs=gr.Textbox(label="π Describe Your Symptoms", placeholder="e.g., experiencing chest pain and shortness of breath...", lines=3),
|
|
|
outputs=gr.Textbox(label="π Specialist Recommendation", interactive=True),
|
|
|
title="π₯ Medical Specialist Recommender",
|
|
|
description="Enter your symptoms to receive a recommendation for the appropriate medical specialist.",
|
|
|
theme="compact",
|
|
|
allow_flagging="never",
|
|
|
examples=[
|
|
|
["I have persistent headaches and dizziness."],
|
|
|
["My skin has developed a red, itchy rash."],
|
|
|
["I'm experiencing joint pain and stiffness in the mornings."]
|
|
|
],
|
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
iface.launch()
|
|
|
|