import gradio as gr from transformers import pipeline # Load Hugging Face pipelines ner_pipeline = pipeline("ner", model="dslim/bert-base-NER") sentiment_pipeline = pipeline("sentiment-analysis") summarization_pipeline = pipeline("summarization", model="facebook/bart-large-cnn") conversation_pipeline = pipeline("text-generation", model="microsoft/DialoGPT-medium") # Function to process user input def ai_doctor_interaction(user_input, chat_history=[]): # Perform NER ner_results = ner_pipeline(user_input) entities = [f"{entity['entity_group']}: {entity['word']}" for entity in ner_results] # Perform Sentiment Analysis sentiment_results = sentiment_pipeline(user_input) sentiment = f"{sentiment_results[0]['label']} (Confidence: {sentiment_results[0]['score']:.2f})" # Perform Summarization summary = summarization_pipeline(user_input, max_length=50, min_length=10, do_sample=False)[0]['summary_text'] # Generate AI Doctor response ai_response = conversation_pipeline(user_input, max_length=100, num_return_sequences=1)[0]["generated_text"] # Combine results response = f""" **Entities Identified**: {', '.join(entities)} **Sentiment**: {sentiment} **Summary**: {summary} **AI Doctor Response**: {ai_response} """ chat_history.append(("You", user_input)) chat_history.append(("AI Doctor", response)) return chat_history, chat_history # Gradio interface with gr.Blocks() as demo: gr.Markdown("

AI Doctor Avatar

") gr.Markdown("

Interact with the AI Doctor to resolve your health-related queries.

") with gr.Row(): with gr.Column(scale=1): gr.Markdown("

AI Doctor Avatar

") gr.HTML("""
""") with gr.Column(scale=2): chatbot = gr.Chatbot(label="AI Doctor Chat Interface", height=400) user_input = gr.Textbox(label="Your Message", placeholder="Type your question here...", lines=2) with gr.Row(): submit_button = gr.Button("Send", variant="primary") clear_button = gr.Button("Clear Chat", variant="secondary") # Define interactions submit_button.click(ai_doctor_interaction, inputs=[user_input, chatbot], outputs=[chatbot, chatbot]) clear_button.click(lambda: [], inputs=[], outputs=[chatbot]) # Launch the Gradio app demo.launch()