Spaces:
Sleeping
Sleeping
| 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() |