import openai import gradio as gr from deep_translator import GoogleTranslator openai.api_key = "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" # Replace with your OpenAI API key language_codes = { "English": "en", "Tamil": "ta", "Telugu": "te", "Kannada": "kn", "Malayalam": "ml", "Hindi": "hi" } def translate_input(text, lang): if lang != "English": return GoogleTranslator(source=language_codes[lang], target="en").translate(text) return text def translate_output(text, lang): if lang != "English": return GoogleTranslator(source="en", target=language_codes[lang]).translate(text) return text def chatbot(user_input, language): try: translated_input = translate_input(user_input, language) response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are a polite hospital receptionist."}, {"role": "user", "content": translated_input} ] ) reply = response.choices[0].message.content final_reply = translate_output(reply, language) return final_reply except Exception as e: return f"❌ Error: {str(e)}" iface = gr.Interface( fn=chatbot, inputs=[ gr.Textbox(label="Ask your hospital-related question"), gr.Dropdown(choices=list(language_codes.keys()), label="Select Language", value="English") ], outputs=gr.Textbox(label="Receptionist's Response"), title="🏥 Multilingual Hospital Receptionist Chatbot" ) iface.launch() import gradio as gr # your function and UI logic here... demo = gr.Interface(fn=your_function, inputs=..., outputs=...) demo.launch()