File size: 1,812 Bytes
03d8f07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from modules.audio_processing import transcribe_audio
from modules.image_processing import encode_image_to_base64
from modules.text_processing import get_user_query
#from modules.ai_response import generate_medical_response
from modules.gemini_response import generate_medical_response

def process_inputs(text_input, audio_file, image_file, history):
    transcribed_text = None
    if audio_file:
        transcribed_text = transcribe_audio(audio_file)

    query = get_user_query(text_input, transcribed_text)
    image_base64 = encode_image_to_base64(image_file) if image_file else None

    if history is None:
        history = []

    # Add user message to history
    history.append({"role": "user", "content": query})

    # Get doctor response
    doctor_response = generate_medical_response(query, image_base64=image_base64, history=history)

    # Add doctor response to history
    history.append({"role": "assistant", "content": doctor_response})

    return transcribed_text or "", doctor_response, history

iface = gr.Interface(
    fn=process_inputs,
    inputs=[
        gr.Textbox(label="Type your medical question (optional)"),
        gr.Audio(sources=["microphone"], type="filepath", label="Speak your question (optional)"),
        gr.Image(type="filepath", label="Upload a related medical image (optional)"),
        gr.State([])  # <-- Chat history
    ],
    outputs=[
        gr.Textbox(label="Transcribed Audio"),
        gr.Textbox(label="Doctor's Detailed Response"),
        gr.State()  # <-- Return updated history
    ],
    title="Multimodal Medical AI Chatbot",
    description="Ask about diseases or chronic illnesses using text, audio, or images."
)

if __name__ == "__main__":
    iface.launch(debug=True)