File size: 4,743 Bytes
82bb0c6
e1f6d3a
832626b
e1f6d3a
 
eb1e9f9
e1f6d3a
7a51583
c1bade9
e1f6d3a
 
c4ea1ea
 
e1f6d3a
c4ea1ea
e1f6d3a
c4ea1ea
33fb4a9
81d18e0
509006d
e1f6d3a
c1bade9
82bb0c6
e1f6d3a
b70d441
e1f6d3a
81d18e0
3b92d97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1f6d3a
 
 
 
 
 
a0a333b
ba3c1b9
 
 
 
 
e1f6d3a
 
 
a0a333b
7079496
 
eb1e9f9
7079496
eb1e9f9
7079496
 
eb1e9f9
7079496
eb1e9f9
a0a333b
 
 
7079496
eb1e9f9
a0a333b
e1f6d3a
b70d441
82bb0c6
e1f6d3a
 
 
 
 
 
509006d
7079496
 
 
 
eb1e9f9
7079496
509006d
e1f6d3a
 
 
c1bade9
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
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()