Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,9 +72,8 @@ Question:
|
|
| 72 |
return groq_query(prompt)
|
| 73 |
|
| 74 |
# =========================================
|
| 75 |
-
# Redesigned Gradio UI (Fixed
|
| 76 |
# =========================================
|
| 77 |
-
import gradio as gr
|
| 78 |
|
| 79 |
# Sample mock questions from your HOD messages
|
| 80 |
mock_questions = [
|
|
@@ -90,11 +89,11 @@ mock_questions = [
|
|
| 90 |
"Who leads the Languages and Cultural Studies Department?"
|
| 91 |
]
|
| 92 |
|
| 93 |
-
#
|
| 94 |
def set_question(q_text, txt_box):
|
| 95 |
return txt_box.update(value=q_text)
|
| 96 |
|
| 97 |
-
#
|
| 98 |
def respond(message, history):
|
| 99 |
if not history:
|
| 100 |
history = []
|
|
@@ -109,40 +108,50 @@ def respond(message, history):
|
|
| 109 |
return history, "" # update chat and clear input
|
| 110 |
|
| 111 |
with gr.Blocks() as demo:
|
| 112 |
-
#
|
| 113 |
-
gr.Markdown(
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
#
|
| 116 |
gr.Markdown(
|
| 117 |
"""
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
| 123 |
)
|
| 124 |
|
| 125 |
# Main layout: sidebar + chatbot
|
| 126 |
with gr.Row():
|
| 127 |
-
# Left
|
| 128 |
with gr.Column(scale=1):
|
| 129 |
gr.Markdown("### 💡 Sample Questions")
|
| 130 |
|
| 131 |
# The textbox will be shared with buttons
|
| 132 |
user_input = gr.Textbox(placeholder="Type your question here...", lines=2)
|
| 133 |
-
|
| 134 |
# Create buttons for each mock question
|
| 135 |
for q in mock_questions:
|
| 136 |
gr.Button(q, elem_classes="mock-btn").click(
|
| 137 |
-
set_question,
|
|
|
|
|
|
|
| 138 |
)
|
| 139 |
|
| 140 |
-
# Right: Chatbot
|
| 141 |
with gr.Column(scale=3):
|
| 142 |
chatbot = gr.Chatbot()
|
| 143 |
send_btn = gr.Button("Send", variant="primary")
|
| 144 |
|
| 145 |
-
#
|
| 146 |
-
send_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
|
|
|
| 148 |
demo.launch()
|
|
|
|
| 72 |
return groq_query(prompt)
|
| 73 |
|
| 74 |
# =========================================
|
| 75 |
+
# Redesigned Gradio UI (Fixed Version)
|
| 76 |
# =========================================
|
|
|
|
| 77 |
|
| 78 |
# Sample mock questions from your HOD messages
|
| 79 |
mock_questions = [
|
|
|
|
| 89 |
"Who leads the Languages and Cultural Studies Department?"
|
| 90 |
]
|
| 91 |
|
| 92 |
+
# Function to set a mock question into the textbox
|
| 93 |
def set_question(q_text, txt_box):
|
| 94 |
return txt_box.update(value=q_text)
|
| 95 |
|
| 96 |
+
# Function to send question to chatbot
|
| 97 |
def respond(message, history):
|
| 98 |
if not history:
|
| 99 |
history = []
|
|
|
|
| 108 |
return history, "" # update chat and clear input
|
| 109 |
|
| 110 |
with gr.Blocks() as demo:
|
| 111 |
+
# App Title (centered)
|
| 112 |
+
gr.Markdown(
|
| 113 |
+
"<h1 style='text-align: center; color: #2c3e50;'>🎓 Baltistan Academic Assistant</h1>"
|
| 114 |
+
)
|
| 115 |
|
| 116 |
+
# Description (centered using HTML tags inside Markdown)
|
| 117 |
gr.Markdown(
|
| 118 |
"""
|
| 119 |
+
<div style="text-align:center; color:#34495e; font-size:15px; max-width:900px; margin:auto;">
|
| 120 |
+
Welcome to the Baltistan Academic Assistant! This AI-based chatbot helps students, faculty, and visitors
|
| 121 |
+
find official messages and guidance from all department heads of the University of Baltistan.
|
| 122 |
+
🧠 It answers questions **strictly based on the official head messages** collected from the university website.
|
| 123 |
+
</div>
|
| 124 |
+
"""
|
| 125 |
)
|
| 126 |
|
| 127 |
# Main layout: sidebar + chatbot
|
| 128 |
with gr.Row():
|
| 129 |
+
# Left sidebar with mock questions
|
| 130 |
with gr.Column(scale=1):
|
| 131 |
gr.Markdown("### 💡 Sample Questions")
|
| 132 |
|
| 133 |
# The textbox will be shared with buttons
|
| 134 |
user_input = gr.Textbox(placeholder="Type your question here...", lines=2)
|
| 135 |
+
|
| 136 |
# Create buttons for each mock question
|
| 137 |
for q in mock_questions:
|
| 138 |
gr.Button(q, elem_classes="mock-btn").click(
|
| 139 |
+
set_question,
|
| 140 |
+
inputs=[gr.State(q), user_input],
|
| 141 |
+
outputs=user_input
|
| 142 |
)
|
| 143 |
|
| 144 |
+
# Right: Chatbot UI
|
| 145 |
with gr.Column(scale=3):
|
| 146 |
chatbot = gr.Chatbot()
|
| 147 |
send_btn = gr.Button("Send", variant="primary")
|
| 148 |
|
| 149 |
+
# Bind send button to chatbot response
|
| 150 |
+
send_btn.click(
|
| 151 |
+
respond,
|
| 152 |
+
inputs=[user_input, chatbot],
|
| 153 |
+
outputs=[chatbot, user_input]
|
| 154 |
+
)
|
| 155 |
|
| 156 |
+
# Launch the redesigned UI
|
| 157 |
demo.launch()
|