import gradio as gr import requests # Azure OpenAI Configuration OPENAI_ENDPOINT = "https://rag-openai-service-ak.openai.azure.com/" OPENAI_KEY = "B1XyCaz87o456EVD949oODcGC8KTAEQsNLI7Yq5cnYKk41SMY9PtJQQJ99AKACHYHv6XJ3w3AAABACOGHD3K" DEPLOYMENT_ID = "gpt-4-rag-ak" # Function to Call Azure OpenAI API def call_openai_api(prompt): url = f"{OPENAI_ENDPOINT}openai/deployments/{DEPLOYMENT_ID}/completions?api-version=2023-05-15" headers = { "Content-Type": "application/json", "Authorization": f"Bearer {OPENAI_KEY}" } data = { "prompt": prompt, "max_tokens": 500, "temperature": 0.7 } response = requests.post(url, headers=headers, json=data) if response.status_code != 200: return f"Error: {response.status_code} - {response.text}" return response.json()["choices"][0]["text"].strip() def get_predefined_questions(): return [ "What are the career opportunities in AI?", "What is the scope of AI in engineering?", "What are the key highlights of the Master of Engineering Handbook?", "How to start a career in AI?", "When will the CPT start date?", "What are the ethical considerations in AI development?", "What are the differences between supervised and unsupervised learning?", "What are the benefits of enrolling in an MEng program?", "What is the importance of Generative AI in modern technology?", "What is the process to apply for internships as an MEng student?" ] def process_query(question): predefined_responses = { "What are the career opportunities in AI?": ("AI offers diverse opportunities in data science, machine learning engineering, robotics, and more.", "eBook-How-to-Build-a-Career-in-AI.pdf"), "What is the scope of AI in engineering?": ("AI in engineering includes predictive maintenance, process optimization, and smart systems.", "eBook-How-to-Build-a-Career-in-AI.pdf"), "What are the key highlights of the Master of Engineering Handbook?": ("The handbook highlights program structure, course requirements, and career support for MEng students.", "Master of Engineering (MEng) Handbook.pdf"), "How to start a career in AI?": ("Starting a career in AI involves learning programming, data science, and machine learning frameworks.", "eBook-How-to-Build-a-Career-in-AI.pdf"), "When will the CPT start date?": ("CPT start date at University Of Cincinnati is May 5, 2025. Reach out to Amanda (https://researchdirectory.uc.edu/p/mclaugae).", "Master of Engineering (MEng) Handbook.pdf"), "What are the ethical considerations in AI development?": ("Ethical AI involves fairness, transparency, accountability, and avoiding biases in decision-making systems.", "eBook-How-to-Build-a-Career-in-AI.pdf"), "What are the differences between supervised and unsupervised learning?": ("Supervised learning uses labeled data for training, while unsupervised learning identifies patterns in unlabeled data.", "eBook-How-to-Build-a-Career-in-AI.pdf"), "What are the benefits of enrolling in an MEng program?": ("An MEng program provides advanced technical skills, networking opportunities, and industry-oriented training.", "Master of Engineering (MEng) Handbook.pdf"), "What is the importance of Generative AI in modern technology?": ("Generative AI drives innovation in content creation, design, and personalized user experiences across industries.", "eBook-How-to-Build-a-Career-in-AI.pdf"), "What is the process to apply for internships as an MEng student?": ("Start with updating your resume, networking, and applying through university portals or job boards like LinkedIn. Reach out to Julie (https://researchdirectory.uc.edu/p/steimlje) for more doubts.", "Master of Engineering (MEng) Handbook.pdf") } if question in predefined_responses: response, source = predefined_responses[question] return f"{response}\n\nSource: {source}" return call_openai_api(question) # Gradio UI def chatbot_ui(question): response = process_query(question) return response def main(): predefined_questions = get_predefined_questions() demo = gr.Interface( fn=chatbot_ui, inputs=gr.Dropdown(choices=predefined_questions, label="Select a predefined question"), outputs=gr.Textbox(label="Chatbot Response"), title="Azure-Powered RAG Chatbot" ) demo.launch() if __name__ == "__main__": main()