JenetGhumman commited on
Commit
6744c65
·
verified ·
1 Parent(s): 2216842

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -3,17 +3,17 @@ import gradio as gr
3
  import os
4
  import speech_recognition as sr
5
 
6
- # Securely retrieve the Groq API key from Hugging Face Secrets
7
  groqkey = os.getenv("groqkey")
8
 
9
- # Ensure the API key exists
10
  if not groqkey:
11
  raise ValueError("🚨 Error: 'groqkey' is missing! Make sure it is set in Hugging Face Secrets.")
12
 
13
- # Initialize the Groq client
14
  client = Groq(api_key=groqkey)
15
 
16
- # Define chatbot response function
17
  def get_chatbot_response(user_message, insurance_type, country, claim_number, image, language, conversation_history):
18
  """Fetch insurance-related responses from the AI."""
19
 
@@ -78,7 +78,7 @@ def transcribe_audio(audio):
78
  except sr.RequestError:
79
  return "Error processing the audio."
80
 
81
- # Styling and Theme
82
  theme = gr.themes.Base().set(
83
  body_background_fill="linear-gradient(to right, #001F3F, #0052CC)", # Dark navy to royal blue
84
  button_primary_background_fill="linear-gradient(135deg, #FFD700, #FFAA00)", # Golden gradient
@@ -100,13 +100,11 @@ custom_css = """
100
  letter-spacing: 1px;
101
  text-shadow: 1px 1px 5px rgba(255, 215, 0, 0.3);
102
  }
103
-
104
  /* Body text - Gold on Dark Background */
105
  body, .gradio-container {
106
  color: #FFD700 !important;
107
  font-family: 'Inter', sans-serif;
108
  }
109
-
110
  /* Chat messages - Minimalist design */
111
  .chat-message {
112
  background: rgba(255, 255, 255, 0.05);
@@ -115,7 +113,6 @@ body, .gradio-container {
115
  backdrop-filter: blur(8px);
116
  color: white !important;
117
  }
118
-
119
  /* Buttons */
120
  button.primary {
121
  background: linear-gradient(135deg, #FFD700, #FFAA00);
@@ -127,14 +124,13 @@ button.primary {
127
  padding: 10px 20px;
128
  transition: all 0.3s ease-in-out;
129
  }
130
-
131
  button.primary:hover {
132
  transform: scale(1.1);
133
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.7);
134
  }
135
  """
136
 
137
- # Build Gradio Interface
138
  with gr.Blocks(theme=theme, css=custom_css) as demo:
139
  gr.HTML("<h2 class='title-text'>🛡️ AI Insurance Chatbot</h2>")
140
  gr.Markdown("### Select your insurance type, country, and ask your question.")
@@ -162,13 +158,13 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
162
 
163
  conversation_state = gr.State([])
164
 
165
- chatbot = gr.Chatbot(label="Chat History", type="messages") # Fix: Set type to "messages"
166
 
167
  clear_button = gr.Button("Clear Chat History")
168
  clear_button.click(lambda: [], outputs=[conversation_state, chatbot])
169
 
170
  question_input = gr.Textbox(label="Ask your question...", placeholder="Describe your insurance question...", interactive=True)
171
- image_input = gr.File(label="Upload an image (optional)", type="filepath") # Fix: Change type to "filepath"
172
  voice_input = gr.Audio(label="Speak your question (optional)", type="filepath")
173
 
174
  submit_btn = gr.Button("Send")
@@ -185,4 +181,4 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
185
  outputs=[conversation_state, chatbot]
186
  )
187
 
188
- demo.launch()
 
3
  import os
4
  import speech_recognition as sr
5
 
6
+ # Securely retrieve the Groq API key from Hugging Face Secrets
7
  groqkey = os.getenv("groqkey")
8
 
9
+ # Ensure the API key exists
10
  if not groqkey:
11
  raise ValueError("🚨 Error: 'groqkey' is missing! Make sure it is set in Hugging Face Secrets.")
12
 
13
+ # Initialize the Groq client
14
  client = Groq(api_key=groqkey)
15
 
16
+ # Define chatbot response function
17
  def get_chatbot_response(user_message, insurance_type, country, claim_number, image, language, conversation_history):
18
  """Fetch insurance-related responses from the AI."""
19
 
 
78
  except sr.RequestError:
79
  return "Error processing the audio."
80
 
81
+ # Styling and Theme
82
  theme = gr.themes.Base().set(
83
  body_background_fill="linear-gradient(to right, #001F3F, #0052CC)", # Dark navy to royal blue
84
  button_primary_background_fill="linear-gradient(135deg, #FFD700, #FFAA00)", # Golden gradient
 
100
  letter-spacing: 1px;
101
  text-shadow: 1px 1px 5px rgba(255, 215, 0, 0.3);
102
  }
 
103
  /* Body text - Gold on Dark Background */
104
  body, .gradio-container {
105
  color: #FFD700 !important;
106
  font-family: 'Inter', sans-serif;
107
  }
 
108
  /* Chat messages - Minimalist design */
109
  .chat-message {
110
  background: rgba(255, 255, 255, 0.05);
 
113
  backdrop-filter: blur(8px);
114
  color: white !important;
115
  }
 
116
  /* Buttons */
117
  button.primary {
118
  background: linear-gradient(135deg, #FFD700, #FFAA00);
 
124
  padding: 10px 20px;
125
  transition: all 0.3s ease-in-out;
126
  }
 
127
  button.primary:hover {
128
  transform: scale(1.1);
129
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.7);
130
  }
131
  """
132
 
133
+ # Build Gradio Interface
134
  with gr.Blocks(theme=theme, css=custom_css) as demo:
135
  gr.HTML("<h2 class='title-text'>🛡️ AI Insurance Chatbot</h2>")
136
  gr.Markdown("### Select your insurance type, country, and ask your question.")
 
158
 
159
  conversation_state = gr.State([])
160
 
161
+ chatbot = gr.Chatbot(label="Chat History", type="messages") # Fix: Set type to "messages"
162
 
163
  clear_button = gr.Button("Clear Chat History")
164
  clear_button.click(lambda: [], outputs=[conversation_state, chatbot])
165
 
166
  question_input = gr.Textbox(label="Ask your question...", placeholder="Describe your insurance question...", interactive=True)
167
+ image_input = gr.File(label="Upload an image (optional)", type="filepath") # Fix: Change type to "filepath"
168
  voice_input = gr.Audio(label="Speak your question (optional)", type="filepath")
169
 
170
  submit_btn = gr.Button("Send")
 
181
  outputs=[conversation_state, chatbot]
182
  )
183
 
184
+ demo.launch()