Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,28 +72,72 @@ Question:
|
|
| 72 |
return groq_query(prompt)
|
| 73 |
|
| 74 |
# =========================================
|
| 75 |
-
# 6️⃣ Gradio UI
|
| 76 |
# =========================================
|
| 77 |
-
with gr.Blocks() as demo:
|
| 78 |
-
gr.Markdown("## 🎓 Baltistan Academic Assistant")
|
| 79 |
-
|
| 80 |
-
chatbot = gr.Chatbot() # Chat UI
|
| 81 |
-
msg = gr.Textbox(placeholder="Ask your question...")
|
| 82 |
-
|
| 83 |
-
def respond(message, history):
|
| 84 |
-
# Convert history into the required format
|
| 85 |
-
if history is None:
|
| 86 |
-
history = []
|
| 87 |
|
| 88 |
-
user_entry = {"role": "user", "content": message}
|
| 89 |
-
answer = rag_answer(message)
|
| 90 |
-
assistant_entry = {"role": "assistant", "content": answer}
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
demo.launch()
|
|
|
|
| 72 |
return groq_query(prompt)
|
| 73 |
|
| 74 |
# =========================================
|
| 75 |
+
# 6️⃣ Redesigned Gradio UI
|
| 76 |
# =========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
# Sample mock questions from your HOD messages
|
| 80 |
+
mock_questions = [
|
| 81 |
+
"What is the focus of the Botany Department?",
|
| 82 |
+
"Who is the Head of Chemistry Department?",
|
| 83 |
+
"What programs does the Computer Science Department offer?",
|
| 84 |
+
"What environmental challenges does the Earth & Environmental Science Dept address?",
|
| 85 |
+
"Who is the Head of Mathematics Department?",
|
| 86 |
+
"What subjects are taught in the Zoology Department?",
|
| 87 |
+
"What is the mission of Archaeology & Heritage Studies Department?",
|
| 88 |
+
"What programs are offered in Business Management, Commerce, and Economics?",
|
| 89 |
+
"What is the goal of Educational Development Department?",
|
| 90 |
+
"Who leads the Languages and Cultural Studies Department?"
|
| 91 |
+
]
|
| 92 |
|
| 93 |
+
with gr.Blocks() as demo:
|
| 94 |
+
# Top-centered title
|
| 95 |
+
gr.Markdown("## 🎓 Baltistan Academic Assistant", elem_id="title",
|
| 96 |
+
elem_classes="center-text")
|
| 97 |
+
|
| 98 |
+
# Paragraph about the application
|
| 99 |
+
gr.Markdown(
|
| 100 |
+
"""
|
| 101 |
+
Welcome to the Baltistan Academic Assistant! This AI-powered chatbot is built to help students, faculty, and visitors access messages, updates, and academic guidance from all department heads of the University of Baltistan.
|
| 102 |
+
The information is sourced from the official university website and compiled to provide accurate answers to your questions about courses, faculty, research, and departmental objectives.
|
| 103 |
+
""",
|
| 104 |
+
elem_id="description"
|
| 105 |
+
)
|
| 106 |
|
| 107 |
+
# Main layout: sidebar on left, chatbot on right
|
| 108 |
+
with gr.Row():
|
| 109 |
+
# Left sidebar with mock questions
|
| 110 |
+
with gr.Column(scale=1):
|
| 111 |
+
gr.Markdown("### 💡 Sample Questions")
|
| 112 |
+
for q in mock_questions:
|
| 113 |
+
def set_question(q_text, txt_box):
|
| 114 |
+
return txt_box.update(value=q_text)
|
| 115 |
+
# Each question is a button to fill the input
|
| 116 |
+
gr.Button(q, elem_classes="mock-btn").click(
|
| 117 |
+
set_question, [gr.State(q), None], None
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# Right column: chatbot
|
| 121 |
+
with gr.Column(scale=3):
|
| 122 |
+
chatbot = gr.Chatbot()
|
| 123 |
+
user_input = gr.Textbox(placeholder="Type your question here...", lines=2)
|
| 124 |
+
send_btn = gr.Button("Send")
|
| 125 |
+
|
| 126 |
+
def respond(message, history):
|
| 127 |
+
if not history:
|
| 128 |
+
history = []
|
| 129 |
+
|
| 130 |
+
user_entry = {"role": "user", "content": message}
|
| 131 |
+
answer = rag_answer(message)
|
| 132 |
+
assistant_entry = {"role": "assistant", "content": answer}
|
| 133 |
+
|
| 134 |
+
history.append(user_entry)
|
| 135 |
+
history.append(assistant_entry)
|
| 136 |
+
|
| 137 |
+
return history, "" # update chat and clear input
|
| 138 |
+
|
| 139 |
+
# Bind send button to chatbot response
|
| 140 |
+
send_btn.click(respond, [user_input, chatbot], [chatbot, user_input])
|
| 141 |
+
|
| 142 |
+
# Launch the redesigned UI
|
| 143 |
demo.launch()
|