Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import requests
|
|
| 3 |
|
| 4 |
# Azure OpenAI Configuration
|
| 5 |
OPENAI_ENDPOINT = "https://rag-openai-service-ak.openai.azure.com/"
|
| 6 |
-
OPENAI_KEY = "
|
| 7 |
DEPLOYMENT_ID = "gpt-4-rag-ak"
|
| 8 |
|
| 9 |
# Function to Call Azure OpenAI API
|
|
@@ -25,7 +25,7 @@ def call_openai_api(prompt):
|
|
| 25 |
|
| 26 |
return response.json()["choices"][0]["text"].strip()
|
| 27 |
|
| 28 |
-
# Predefined Questions
|
| 29 |
def get_predefined_questions():
|
| 30 |
return [
|
| 31 |
"What are the career opportunities in AI?",
|
|
@@ -40,23 +40,23 @@ def get_predefined_questions():
|
|
| 40 |
"What is the process to apply for internships as an MEng student?"
|
| 41 |
]
|
| 42 |
|
| 43 |
-
# Function to Process Query
|
| 44 |
def process_query(question):
|
| 45 |
predefined_responses = {
|
| 46 |
-
"What are the career opportunities in AI?": "AI offers diverse opportunities in data science, machine learning engineering, robotics, and more.",
|
| 47 |
-
"What is the scope of AI in engineering?": "AI in engineering includes predictive maintenance, process optimization, and smart systems.",
|
| 48 |
-
"What are the key highlights of the Master of Engineering Handbook?": "The handbook highlights program structure, course requirements, and career support for MEng students.",
|
| 49 |
-
"How to start a career in AI?": "Starting a career in AI involves learning programming, data science, and machine learning frameworks.",
|
| 50 |
-
"When will the CPT start date?": "CPT start
|
| 51 |
-
"What are the ethical considerations in AI development?": "Ethical AI involves fairness, transparency, accountability, and avoiding biases in decision-making systems.",
|
| 52 |
-
"What are the differences between supervised and unsupervised learning?": "Supervised learning uses labeled data for training, while unsupervised learning identifies patterns in unlabeled data.",
|
| 53 |
-
"What are the benefits of enrolling in an MEng program?": "An MEng program provides advanced technical skills, networking opportunities, and industry-oriented training.",
|
| 54 |
-
"What is the importance of Generative AI in modern technology?": "Generative AI drives innovation in content creation, design, and personalized user experiences across industries.",
|
| 55 |
-
"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."
|
| 56 |
}
|
| 57 |
|
| 58 |
if question in predefined_responses:
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
# Use Azure OpenAI for unlisted questions
|
| 62 |
return call_openai_api(question)
|
|
@@ -69,18 +69,17 @@ def chatbot_ui(question):
|
|
| 69 |
def main():
|
| 70 |
predefined_questions = get_predefined_questions()
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
clear_btn.click(lambda: "", inputs=None, outputs=response_output)
|
| 84 |
|
| 85 |
demo.launch()
|
| 86 |
|
|
|
|
| 3 |
|
| 4 |
# Azure OpenAI Configuration
|
| 5 |
OPENAI_ENDPOINT = "https://rag-openai-service-ak.openai.azure.com/"
|
| 6 |
+
OPENAI_KEY = "B1XyCaz87o456EVD949oODcGC8KTAEQsNLI7Yq5cnYKk41SMY9PtJQQJ99AKACHYHv6XJ3w3AAABACOGAaCZ"
|
| 7 |
DEPLOYMENT_ID = "gpt-4-rag-ak"
|
| 8 |
|
| 9 |
# Function to Call Azure OpenAI API
|
|
|
|
| 25 |
|
| 26 |
return response.json()["choices"][0]["text"].strip()
|
| 27 |
|
| 28 |
+
# Predefined Questions and Sources
|
| 29 |
def get_predefined_questions():
|
| 30 |
return [
|
| 31 |
"What are the career opportunities in AI?",
|
|
|
|
| 40 |
"What is the process to apply for internships as an MEng student?"
|
| 41 |
]
|
| 42 |
|
|
|
|
| 43 |
def process_query(question):
|
| 44 |
predefined_responses = {
|
| 45 |
+
"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"),
|
| 46 |
+
"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"),
|
| 47 |
+
"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 2023.pdf"),
|
| 48 |
+
"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"),
|
| 49 |
+
"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 2023.pdf"),
|
| 50 |
+
"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"),
|
| 51 |
+
"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"),
|
| 52 |
+
"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 2023.pdf"),
|
| 53 |
+
"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"),
|
| 54 |
+
"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 2023.pdf")
|
| 55 |
}
|
| 56 |
|
| 57 |
if question in predefined_responses:
|
| 58 |
+
response, source = predefined_responses[question]
|
| 59 |
+
return f"Response: {response}\n\nSource: {source}"
|
| 60 |
|
| 61 |
# Use Azure OpenAI for unlisted questions
|
| 62 |
return call_openai_api(question)
|
|
|
|
| 69 |
def main():
|
| 70 |
predefined_questions = get_predefined_questions()
|
| 71 |
|
| 72 |
+
demo = gr.Interface(
|
| 73 |
+
fn=chatbot_ui,
|
| 74 |
+
inputs=gr.Dropdown(choices=predefined_questions, label="Select a predefined question"),
|
| 75 |
+
outputs=gr.Textbox(label="Chatbot Response"),
|
| 76 |
+
title="Azure-Powered RAG Chatbot",
|
| 77 |
+
live=True,
|
| 78 |
+
theme="default",
|
| 79 |
+
examples=predefined_questions,
|
| 80 |
+
allow_flagging="never",
|
| 81 |
+
layout="vertical"
|
| 82 |
+
)
|
|
|
|
| 83 |
|
| 84 |
demo.launch()
|
| 85 |
|