File size: 3,007 Bytes
770451b
a004d4a
 
fcec4c5
 
 
 
 
a004d4a
 
 
fcec4c5
a004d4a
 
 
 
 
 
 
 
 
 
fcec4c5
b963626
1fea0a1
fcec4c5
a004d4a
1fea0a1
 
 
 
a004d4a
 
 
 
 
 
 
fcec4c5
 
a004d4a
 
 
1fea0a1
 
 
 
 
 
 
 
 
a004d4a
1fea0a1
 
 
 
 
a004d4a
 
 
 
 
 
 
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
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("<h1 style='text-align: center;'>AI Doctor Avatar</h1>")
    gr.Markdown("<p style='text-align: center;'>Interact with the AI Doctor to resolve your health-related queries.</p>")
    
    with gr.Row():
        with gr.Column(scale=1):
            gr.Markdown("<h3 style='text-align: center;'>AI Doctor Avatar</h3>")
            gr.HTML("""
                <div style="position: relative; overflow: hidden; aspect-ratio: 1920/1080">
                    <iframe src="https://ff-resource.aistudios.com/2025-05-01/6813589d929f360ef7c28ecd.completed.mp4" 
                            loading="lazy" title="AI Doctor Avatar" allow="encrypted-media; fullscreen;" 
                            style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; border: none; padding: 0; margin: 0; overflow:hidden;">
                    </iframe>
                </div>
            """)
        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()