Spaces:
Running
Running
File size: 894 Bytes
48b9342 d7eb662 48b9342 d7eb662 |
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 |
import gradio as gr
from transformers import AutoModelForMaskedLM, AutoTokenizer, pipeline
# Load ClinicalBERT model
model_name = "emilyalsentzer/Bio_ClinicalBERT"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForMaskedLM.from_pretrained(model_name)
# Create a text generation pipeline
nlp_pipeline = pipeline("fill-mask", model=model, tokenizer=tokenizer)
# Function to interact with ClinicalBERT
def medical_chatbot(user_input):
response = nlp_pipeline(user_input.replace("[MASK]", ""))
return response[0]["sequence"] # Returns the most likely sentence
# Gradio UI
interface = gr.Interface(
fn=medical_chatbot,
inputs=gr.Textbox(lines=2, placeholder="Enter medical query with [MASK]..."),
outputs="text",
title="Medical Chatbot",
description="Ask medical questions. Example: 'Patient shows symptoms of [MASK]'."
)
interface.launch()
|