asthaaa300 commited on
Commit
c54f5d5
·
verified ·
1 Parent(s): e2ce2c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -100
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: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%) !important;
68
- font-family: 'Inter', sans-serif !important;
69
  }
70
 
71
  /* Header styling */
72
- h1.gr-text-center {
73
- font-size: 2.5rem !important;
74
- color: #1a365d !important;
75
- text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1) !important;
76
- padding: 1.5rem 0 !important;
77
- border-bottom: 2px solid rgba(26, 54, 93, 0.1) !important;
78
  }
79
 
80
- /* Chat window */
81
- .chat-window {
82
- background: rgba(255, 255, 255, 0.7) !important;
83
- border-radius: 16px !important;
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
- /* Message styling */
92
- .message.user {
93
- background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%) !important;
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
- .message.bot {
102
- background: linear-gradient(135deg, #e6f3ff 0%, #f0f8ff 100%) !important;
103
- color: #1a365d !important;
104
- border-radius: 16px 16px 16px 2px !important;
105
- padding: 15px 20px !important;
106
- margin: 10px 0 !important;
107
  border: 1px solid rgba(26, 54, 93, 0.1) !important;
108
- box-shadow: 0 4px 12px rgba(26, 54, 93, 0.08) !important;
109
  }
110
 
111
- /* Input area styling */
112
- .input-row {
113
- background: rgba(255, 255, 255, 0.9) !important;
 
 
 
 
 
 
 
 
114
  border-radius: 12px !important;
115
- padding: 10px !important;
116
- box-shadow: 0 4px 12px rgba(26, 54, 93, 0.08) !important;
 
117
  }
118
 
119
- textarea {
120
- background: rgba(255, 255, 255, 0.8) !important;
121
- border: 1px solid rgba(26, 54, 93, 0.1) !important;
 
122
  border-radius: 8px !important;
123
- padding: 12px !important;
124
- font-size: 1rem !important;
125
- transition: all 0.3s ease !important;
126
  }
127
 
128
- textarea:focus {
129
- border-color: #2c5282 !important;
130
- box-shadow: 0 0 0 2px rgba(44, 82, 130, 0.2) !important;
131
  }
132
 
133
- /* Button styling */
134
- button.primary {
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
- button.primary:hover {
145
- transform: translateY(-2px) !important;
146
- box-shadow: 0 4px 12px rgba(26, 54, 93, 0.2) !important;
 
 
 
147
  }
148
 
149
  /* Slider styling */
150
  .gr-slider {
151
- background: rgba(255, 255, 255, 0.9) !important;
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
- # Configure the interface
169
  with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
 
170
  gr.HTML("""
171
- <div style="text-align: center; max-width: 800px; margin: 0 auto; padding: 20px;">
172
- <h1 style="color: #1a365d; font-size: 2.5rem; margin-bottom: 10px;">Maritime Legal Compass</h1>
173
- <p style="color: #2c5282; font-size: 1.1rem; margin-bottom: 20px;">
174
- Your AI-powered guide through Indian maritime law and regulations
175
- </p>
176
  </div>
177
  """)
178
-
179
- chatbot = gr.ChatInterface(
180
- respond,
181
- additional_inputs=[
182
- gr.Textbox(
 
 
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
- elem_classes="system-prompt"
186
- ),
187
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Response Length",
188
- elem_classes="custom-slider"),
189
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Creativity Level",
190
- elem_classes="custom-slider"),
191
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Response Focus",
192
- elem_classes="custom-slider"),
193
- ],
194
- examples=[
195
- ["What are the key regulations governing ports in India?"],
196
- ["Explain the concept of cabotage in Indian maritime law."],
197
- ["What are the legal requirements for registering a vessel in India?"],
198
- ],
199
- cache_examples=False,
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__":