sagar007 commited on
Commit
af611f3
·
verified ·
1 Parent(s): 879dfdc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +136 -15
app.py CHANGED
@@ -87,6 +87,7 @@ def detect_language(text):
87
  if any(ord(char) >= 0x0900 and ord(char) <= 0x097F for char in text): # Devanagari script
88
  return 'hi'
89
  return 'en' # Default to English if no Indic script is detected
 
90
  @spaces.GPU
91
  def generate_response(transcription, sarvam_pipe):
92
  if sarvam_pipe is None:
@@ -121,22 +122,142 @@ def indic_language_assistant(input_type, audio_input, text_input):
121
  except Exception as e:
122
  error_message = f"An error occurred: {str(e)}"
123
  return error_message, error_message, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  # Create Gradio interface
125
- iface = gr.Interface(
126
- fn=indic_language_assistant,
127
- inputs=[
128
- gr.Radio(["audio", "text"], label="Input Type", value="audio"),
129
- gr.Audio(type="filepath", label="Speak (if audio input selected)"),
130
- gr.Textbox(label="Type your message (if text input selected)")
131
- ],
132
- outputs=[
133
- gr.Textbox(label="Transcription/Input"),
134
- gr.Textbox(label="Generated Response"),
135
- gr.Audio(label="Audio Response")
136
- ],
137
- title="Indic Language Virtual Assistant",
138
- description="Speak or type in any supported Indic language or English. The assistant will respond in text and audio."
139
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  # Launch the app
142
  iface.launch()
 
87
  if any(ord(char) >= 0x0900 and ord(char) <= 0x097F for char in text): # Devanagari script
88
  return 'hi'
89
  return 'en' # Default to English if no Indic script is detected
90
+
91
  @spaces.GPU
92
  def generate_response(transcription, sarvam_pipe):
93
  if sarvam_pipe is None:
 
122
  except Exception as e:
123
  error_message = f"An error occurred: {str(e)}"
124
  return error_message, error_message, None
125
+
126
+ # Updated Custom CSS
127
+ custom_css = """
128
+ body {
129
+ background-color: #0b0f19;
130
+ color: #e2e8f0;
131
+ font-family: 'Arial', sans-serif;
132
+ }
133
+ #custom-header {
134
+ text-align: center;
135
+ padding: 20px 0;
136
+ background-color: #1a202c;
137
+ margin-bottom: 20px;
138
+ border-radius: 10px;
139
+ }
140
+ #custom-header h1 {
141
+ font-size: 2.5rem;
142
+ margin-bottom: 0.5rem;
143
+ }
144
+ #custom-header h1 .blue {
145
+ color: #60a5fa;
146
+ }
147
+ #custom-header h1 .pink {
148
+ color: #f472b6;
149
+ }
150
+ #custom-header h2 {
151
+ font-size: 1.5rem;
152
+ color: #94a3b8;
153
+ }
154
+ .suggestions {
155
+ display: flex;
156
+ justify-content: center;
157
+ flex-wrap: wrap;
158
+ gap: 1rem;
159
+ margin: 20px 0;
160
+ }
161
+ .suggestion {
162
+ background-color: #1e293b;
163
+ border-radius: 0.5rem;
164
+ padding: 1rem;
165
+ display: flex;
166
+ align-items: center;
167
+ transition: transform 0.3s ease;
168
+ width: 200px;
169
+ }
170
+ .suggestion:hover {
171
+ transform: translateY(-5px);
172
+ }
173
+ .suggestion-icon {
174
+ font-size: 1.5rem;
175
+ margin-right: 1rem;
176
+ background-color: #2d3748;
177
+ padding: 0.5rem;
178
+ border-radius: 50%;
179
+ }
180
+ .gradio-container {
181
+ max-width: 100% !important;
182
+ }
183
+ #component-0, #component-1, #component-2 {
184
+ max-width: 100% !important;
185
+ }
186
+ footer {
187
+ text-align: center;
188
+ margin-top: 2rem;
189
+ color: #64748b;
190
+ }
191
+ """
192
+
193
+ # Custom HTML for the header
194
+ custom_header = """
195
+ <div id="custom-header">
196
+ <h1>
197
+ <span class="blue">Hello,</span>
198
+ <span class="pink">User</span>
199
+ </h1>
200
+ <h2>How can I help you today?</h2>
201
+ </div>
202
+ """
203
+
204
+ # Custom HTML for suggestions
205
+ custom_suggestions = """
206
+ <div class="suggestions">
207
+ <div class="suggestion">
208
+ <span class="suggestion-icon">🎤</span>
209
+ <p>Speak in any Indic language</p>
210
+ </div>
211
+ <div class="suggestion">
212
+ <span class="suggestion-icon">⌨️</span>
213
+ <p>Type in any Indic language</p>
214
+ </div>
215
+ <div class="suggestion">
216
+ <span class="suggestion-icon">🤖</span>
217
+ <p>Get AI-generated responses</p>
218
+ </div>
219
+ <div class="suggestion">
220
+ <span class="suggestion-icon">🔊</span>
221
+ <p>Listen to audio responses</p>
222
+ </div>
223
+ </div>
224
+ """
225
+
226
  # Create Gradio interface
227
+ with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
228
+ body_background_fill="#0b0f19",
229
+ body_text_color="#e2e8f0",
230
+ button_primary_background_fill="#3b82f6",
231
+ button_primary_background_fill_hover="#2563eb",
232
+ button_primary_text_color="white",
233
+ block_title_text_color="#94a3b8",
234
+ block_label_text_color="#94a3b8",
235
+ )) as iface:
236
+ gr.HTML(custom_header)
237
+ gr.HTML(custom_suggestions)
238
+
239
+ with gr.Row():
240
+ with gr.Column(scale=1):
241
+ gr.Markdown("### Indic Assistant")
242
+ with gr.Column(scale=1, min_width=100):
243
+ gr.Button("Try Advanced Features", size="sm")
244
+
245
+ input_type = gr.Radio(["audio", "text"], label="Input Type", value="audio")
246
+ audio_input = gr.Audio(type="filepath", label="Speak (if audio input selected)")
247
+ text_input = gr.Textbox(label="Type your message (if text input selected)")
248
+
249
+ submit_btn = gr.Button("Submit")
250
+
251
+ output_transcription = gr.Textbox(label="Transcription/Input")
252
+ output_response = gr.Textbox(label="Generated Response")
253
+ output_audio = gr.Audio(label="Audio Response")
254
+
255
+ submit_btn.click(
256
+ fn=indic_language_assistant,
257
+ inputs=[input_type, audio_input, text_input],
258
+ outputs=[output_transcription, output_response, output_audio]
259
+ )
260
+ gr.HTML("<footer>Powered by Indic Language AI</footer>")
261
 
262
  # Launch the app
263
  iface.launch()