asthaaa300
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -60,144 +60,164 @@ def respond(
|
|
60 |
print(f"An error occurred: {e}")
|
61 |
yield f"An error occurred: {e}"
|
62 |
|
63 |
-
# Custom CSS for maritime theme
|
64 |
custom_css = """
|
65 |
/* Global styles */
|
66 |
.gradio-container {
|
67 |
-
background:
|
68 |
-
font-family: 'Inter', sans-serif !important;
|
69 |
}
|
70 |
|
71 |
/* Header styling */
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
border-bottom: 2px solid rgba(26, 54, 93, 0.1) !important;
|
78 |
}
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
box-shadow: 0 8px 32px rgba(26, 54, 93, 0.1) !important;
|
85 |
-
backdrop-filter: blur(8px) !important;
|
86 |
-
border: 1px solid rgba(255, 255, 255, 0.2) !important;
|
87 |
-
margin: 20px !important;
|
88 |
-
padding: 20px !important;
|
89 |
}
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
color: white !important;
|
95 |
-
border-radius: 16px 16px 2px 16px !important;
|
96 |
-
padding: 15px 20px !important;
|
97 |
-
margin: 10px 0 !important;
|
98 |
-
box-shadow: 0 4px 12px rgba(26, 54, 93, 0.15) !important;
|
99 |
}
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
border-radius:
|
105 |
-
padding:
|
106 |
-
margin: 10px 0 !important;
|
107 |
border: 1px solid rgba(26, 54, 93, 0.1) !important;
|
108 |
-
|
109 |
}
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
border-radius: 12px !important;
|
115 |
-
padding:
|
116 |
-
|
|
|
117 |
}
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
122 |
border-radius: 8px !important;
|
123 |
-
padding: 12px !important;
|
124 |
-
font-size: 1rem !important;
|
125 |
-
transition: all 0.3s ease !important;
|
126 |
}
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
box-shadow: 0 0 0 2px rgba(44, 82, 130, 0.2) !important;
|
131 |
}
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%) !important;
|
136 |
-
border: none !important;
|
137 |
-
border-radius: 8px !important;
|
138 |
-
padding: 10px 20px !important;
|
139 |
-
color: white !important;
|
140 |
-
font-weight: 600 !important;
|
141 |
-
transition: all 0.3s ease !important;
|
142 |
}
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
147 |
}
|
148 |
|
149 |
/* Slider styling */
|
150 |
.gr-slider {
|
151 |
-
|
152 |
-
border-radius: 8px !important;
|
153 |
-
padding: 15px !important;
|
154 |
-
margin: 10px 0 !important;
|
155 |
-
box-shadow: 0 2px 8px rgba(26, 54, 93, 0.08) !important;
|
156 |
-
}
|
157 |
-
|
158 |
-
/* Examples section */
|
159 |
-
.examples-row {
|
160 |
-
background: rgba(255, 255, 255, 0.7) !important;
|
161 |
-
border-radius: 12px !important;
|
162 |
-
padding: 15px !important;
|
163 |
-
margin-top: 20px !important;
|
164 |
-
box-shadow: 0 4px 12px rgba(26, 54, 93, 0.08) !important;
|
165 |
}
|
166 |
"""
|
167 |
|
168 |
-
#
|
169 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
|
|
170 |
gr.HTML("""
|
171 |
-
<div
|
172 |
-
<h1
|
173 |
-
<p
|
174 |
-
Your AI-powered guide through Indian maritime law and regulations
|
175 |
-
</p>
|
176 |
</div>
|
177 |
""")
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
183 |
value="You are a maritime legal assistant with expertise strictly in Indian maritime law. Provide detailed legal advice and information based on Indian maritime legal principles and regulations.",
|
184 |
label="System Prompt",
|
185 |
-
|
186 |
-
)
|
187 |
-
gr.Slider(
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
# Launch the app
|
203 |
if __name__ == "__main__":
|
|
|
60 |
print(f"An error occurred: {e}")
|
61 |
yield f"An error occurred: {e}"
|
62 |
|
63 |
+
# Custom CSS for maritime theme with sidebar
|
64 |
custom_css = """
|
65 |
/* Global styles */
|
66 |
.gradio-container {
|
67 |
+
background-color: #e6f3ff !important;
|
|
|
68 |
}
|
69 |
|
70 |
/* Header styling */
|
71 |
+
.header-container {
|
72 |
+
text-align: center;
|
73 |
+
padding: 2rem 0;
|
74 |
+
margin-bottom: 2rem;
|
75 |
+
border-bottom: 2px solid rgba(26, 54, 93, 0.1);
|
|
|
76 |
}
|
77 |
|
78 |
+
.header-title {
|
79 |
+
color: #1a365d;
|
80 |
+
font-size: 2.5rem;
|
81 |
+
margin-bottom: 0.5rem;
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
83 |
|
84 |
+
.header-subtitle {
|
85 |
+
color: #2c5282;
|
86 |
+
font-size: 1.1rem;
|
|
|
|
|
|
|
|
|
|
|
87 |
}
|
88 |
|
89 |
+
/* Sidebar styling */
|
90 |
+
.sidebar {
|
91 |
+
background: rgba(255, 255, 255, 0.9) !important;
|
92 |
+
border-radius: 12px !important;
|
93 |
+
padding: 20px !important;
|
|
|
94 |
border: 1px solid rgba(26, 54, 93, 0.1) !important;
|
95 |
+
height: fit-content !important;
|
96 |
}
|
97 |
|
98 |
+
.sidebar-title {
|
99 |
+
font-size: 1.2rem !important;
|
100 |
+
color: #1a365d !important;
|
101 |
+
margin-bottom: 1rem !important;
|
102 |
+
padding-bottom: 0.5rem !important;
|
103 |
+
border-bottom: 2px solid rgba(26, 54, 93, 0.1) !important;
|
104 |
+
}
|
105 |
+
|
106 |
+
/* Chat container */
|
107 |
+
.chat-container {
|
108 |
+
background: rgba(255, 255, 255, 0.7) !important;
|
109 |
border-radius: 12px !important;
|
110 |
+
padding: 20px !important;
|
111 |
+
height: 600px !important;
|
112 |
+
overflow-y: auto !important;
|
113 |
}
|
114 |
|
115 |
+
/* Message styling */
|
116 |
+
.message.user, .message.bot {
|
117 |
+
padding: 12px 16px !important;
|
118 |
+
margin: 8px 0 !important;
|
119 |
border-radius: 8px !important;
|
|
|
|
|
|
|
120 |
}
|
121 |
|
122 |
+
.message.user {
|
123 |
+
background-color: #e1f0ff !important;
|
|
|
124 |
}
|
125 |
|
126 |
+
.message.bot {
|
127 |
+
background-color: #ffffff !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
}
|
129 |
|
130 |
+
/* Input styling */
|
131 |
+
textarea {
|
132 |
+
background-color: #ffffff !important;
|
133 |
+
border: 1px solid rgba(26, 54, 93, 0.2) !important;
|
134 |
+
border-radius: 8px !important;
|
135 |
+
padding: 12px !important;
|
136 |
}
|
137 |
|
138 |
/* Slider styling */
|
139 |
.gr-slider {
|
140 |
+
margin: 1rem 0 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
}
|
142 |
"""
|
143 |
|
144 |
+
# Main application
|
145 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
146 |
+
# Header
|
147 |
gr.HTML("""
|
148 |
+
<div class="header-container">
|
149 |
+
<h1 class="header-title">Maritime Legal Compliance</h1>
|
150 |
+
<p class="header-subtitle">AI-powered assistance for Indian maritime law queries</p>
|
|
|
|
|
151 |
</div>
|
152 |
""")
|
153 |
+
|
154 |
+
# Main layout with sidebar
|
155 |
+
with gr.Row():
|
156 |
+
# Sidebar
|
157 |
+
with gr.Column(scale=1, elem_classes="sidebar"):
|
158 |
+
gr.Markdown("### Configuration", elem_classes="sidebar-title")
|
159 |
+
system_message = gr.Textbox(
|
160 |
value="You are a maritime legal assistant with expertise strictly in Indian maritime law. Provide detailed legal advice and information based on Indian maritime legal principles and regulations.",
|
161 |
label="System Prompt",
|
162 |
+
lines=4
|
163 |
+
)
|
164 |
+
max_tokens = gr.Slider(
|
165 |
+
minimum=1,
|
166 |
+
maximum=2048,
|
167 |
+
value=512,
|
168 |
+
step=1,
|
169 |
+
label="Response Length"
|
170 |
+
)
|
171 |
+
temperature = gr.Slider(
|
172 |
+
minimum=0.1,
|
173 |
+
maximum=4.0,
|
174 |
+
value=0.7,
|
175 |
+
step=0.1,
|
176 |
+
label="Creativity Level"
|
177 |
+
)
|
178 |
+
top_p = gr.Slider(
|
179 |
+
minimum=0.1,
|
180 |
+
maximum=1.0,
|
181 |
+
value=0.95,
|
182 |
+
step=0.05,
|
183 |
+
label="Response Focus"
|
184 |
+
)
|
185 |
+
|
186 |
+
gr.Markdown("### Example Queries", elem_classes="sidebar-title")
|
187 |
+
examples = gr.Examples(
|
188 |
+
examples=[
|
189 |
+
["What are the key regulations governing ports in India?"],
|
190 |
+
["Explain the concept of cabotage in Indian maritime law."],
|
191 |
+
["What are the legal requirements for registering a vessel in India?"],
|
192 |
+
],
|
193 |
+
inputs=[system_message],
|
194 |
+
label="Click on any example to load it"
|
195 |
+
)
|
196 |
+
|
197 |
+
# Main chat area
|
198 |
+
with gr.Column(scale=3):
|
199 |
+
chatbot = gr.Chatbot(height=500, elem_classes="chat-container")
|
200 |
+
msg = gr.Textbox(
|
201 |
+
show_label=False,
|
202 |
+
placeholder="Type your maritime law query here...",
|
203 |
+
container=False
|
204 |
+
)
|
205 |
+
with gr.Row():
|
206 |
+
submit = gr.Button("Send", variant="primary")
|
207 |
+
clear = gr.Button("Clear")
|
208 |
+
|
209 |
+
# Event handlers
|
210 |
+
submit_click = submit.click(
|
211 |
+
respond,
|
212 |
+
inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p],
|
213 |
+
outputs=chatbot
|
214 |
+
)
|
215 |
+
msg_submit = msg.submit(
|
216 |
+
respond,
|
217 |
+
inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p],
|
218 |
+
outputs=chatbot
|
219 |
+
)
|
220 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
221 |
|
222 |
# Launch the app
|
223 |
if __name__ == "__main__":
|