Musawir19 commited on
Commit
1ea000a
·
verified ·
1 Parent(s): a0d946e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -90
app.py CHANGED
@@ -43,7 +43,7 @@ college_data = {
43
  "RO Plant",
44
  ],
45
  "principal": "Prof Irshad Ali Otho",
46
- "rooms": 24,
47
  "established": "2003",
48
  "contact": {
49
  "location": "National Highway N6 bypass Daulatpur",
@@ -55,8 +55,10 @@ college_data = {
55
 
56
  # Step 3: Custom Question Logic
57
  def answer_question(question):
 
58
  question = question.lower()
59
 
 
60
  if "college name" in question or "what is the name" in question:
61
  return f"The name of the college is {college_data['name']}."
62
 
@@ -108,6 +110,7 @@ def answer_question(question):
108
  return f"The college was established in {college_data['established']}."
109
 
110
  else:
 
111
  context = (
112
  f"About the college: {college_data['about']}\n"
113
  f"Programs offered: {', '.join(college_data['programs'])}\n"
@@ -123,102 +126,37 @@ def answer_question(question):
123
  except Exception:
124
  pass
125
 
 
126
  return (
127
  "I'm sorry, I couldn't understand your question. You can ask about programs, teachers, facilities, or contact details."
128
  )
129
 
130
  # Step 4: Create Gradio Interface
131
  with gr.Blocks() as app:
132
- gr.HTML("""
133
- <style>
134
- body {
135
- background-color: white;
136
- color: black;
137
- font-family: Arial, sans-serif;
138
- }
139
- .gradio-container {
140
- background-color: white;
141
- border-radius: 10px;
142
- padding: 20px;
143
- width: 80%;
144
- margin: 0 auto;
145
- }
146
- .gr-textbox input {
147
- background-color: #f0f0f0;
148
- color: black;
149
- }
150
- .gr-button {
151
- background-color: #007BFF;
152
- color: white;
153
- border-radius: 5px;
154
- padding: 10px;
155
- font-size: 16px;
156
- }
157
- .gr-button:hover {
158
- background-color: #0056b3;
159
- }
160
- .gr-markdown {
161
- font-size: 18px;
162
- }
163
- .gr-textbox {
164
- font-size: 22px;
165
- height: 150px;
166
- }
167
- .logo {
168
- text-align: center;
169
- margin-bottom: 20px;
170
- }
171
- .partition {
172
- border-top: 2px solid #FFD700;
173
- margin: 20px 0;
174
- padding-top: 10px;
175
- }
176
- .question-answer-box {
177
- transition: background-color 0.3s ease;
178
- font-size: 22px;
179
- padding: 20px;
180
- border-radius: 8px;
181
- height: 200px;
182
- }
183
- .question-answer-box:hover {
184
- background-color: #e0f7fa;
185
- }
186
- .center-text {
187
- text-align: center;
188
- color: #007BFF;
189
- }
190
- </style>
191
- """)
192
-
193
- # Adding the logo (change the logo path as per your requirement)
194
- gr.HTML("""
195
- <div class="logo">
196
- <img src="https://via.placeholder.com/150" alt="College Logo" />
197
- </div>
198
- """)
199
-
200
- gr.Markdown("<h1 class='center-text' style='font-size: 36px;'>Government Boys Degree College Daulatpur</h1>")
201
-
202
- # About Section
203
  with gr.Row():
204
- gr.Markdown("<h3 class='center-text'>About Us</h3>")
205
- gr.Markdown(college_data["about"])
206
-
207
- gr.HTML("<div class='partition'></div>")
208
-
209
- # Contact Information
210
  with gr.Row():
211
- gr.Markdown("<h3 class='center-text'>Contact Information</h3>")
212
- gr.Markdown(f"Location: {college_data['contact']['location']}\nPhone: {college_data['contact']['phone']}\nEmail: {college_data['contact']['email']}")
 
 
 
 
213
 
214
- gr.HTML("<div class='partition'></div>")
215
-
216
- # Question Answering Section
217
- with gr.Row():
218
- gr.Markdown("<h3 class='center-text'>Ask Me About the College</h3>")
219
- user_input = gr.Textbox(label="Ask your Question:", placeholder="e.g. What programs are offered?", interactive=True)
220
- response_output = gr.Textbox(label="Answer", interactive=False, elem_classes="question-answer-box")
221
- user_input.submit(answer_question, inputs=user_input, outputs=response_output)
222
 
223
- # Launch the app
224
- app.launch(share=True)
 
43
  "RO Plant",
44
  ],
45
  "principal": "Prof Irshad Ali Otho",
46
+ "rooms": 24, # Replaced 'classes' with 'rooms'
47
  "established": "2003",
48
  "contact": {
49
  "location": "National Highway N6 bypass Daulatpur",
 
55
 
56
  # Step 3: Custom Question Logic
57
  def answer_question(question):
58
+ # Lowercase the question for simpler matching
59
  question = question.lower()
60
 
61
+ # Rule-based answers for specific types of questions
62
  if "college name" in question or "what is the name" in question:
63
  return f"The name of the college is {college_data['name']}."
64
 
 
110
  return f"The college was established in {college_data['established']}."
111
 
112
  else:
113
+ # Fallback: Use NLP model
114
  context = (
115
  f"About the college: {college_data['about']}\n"
116
  f"Programs offered: {', '.join(college_data['programs'])}\n"
 
126
  except Exception:
127
  pass
128
 
129
+ # If everything fails
130
  return (
131
  "I'm sorry, I couldn't understand your question. You can ask about programs, teachers, facilities, or contact details."
132
  )
133
 
134
  # Step 4: Create Gradio Interface
135
  with gr.Blocks() as app:
136
+ # Add logo at the top of the page
137
+ gr.Image(value="logo.png", label="College Logo", elem_id="logo", interactive=False)
138
+
139
+ gr.Markdown("<h1 style='text-align: center; color: blue;'>Government Boys Degree College Daulatpur</h1>")
140
+
141
+ # Section for 'About the College'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  with gr.Row():
143
+ gr.Markdown("### About the College")
144
+ about_college = gr.Textbox(value=f"{college_data['about']}\n\n{college_data['extended_about']}",
145
+ label="About the College", interactive=False)
146
+
147
+ # Section for 'Contact Us'
 
148
  with gr.Row():
149
+ gr.Markdown("### Contact Us")
150
+ contact_info = gr.Textbox(value=f"Location: {college_data['contact']['location']}\n"
151
+ f"Phone: {college_data['contact']['phone']}\n"
152
+ f"Email: {college_data['contact']['email']}\n"
153
+ f"Facebook: {college_data['contact']['facebook']}",
154
+ label="Contact Info", interactive=False)
155
 
156
+ # Question and Answer section
157
+ question = gr.Textbox(label="Ask a question about the college")
158
+ answer = gr.Textbox(label="Answer")
159
+ question.submit(answer_question, inputs=question, outputs=answer)
 
 
 
 
160
 
161
+ # Step 5: Launch the App
162
+ app.launch()