TRADMSS commited on
Commit
84ab66d
·
verified ·
1 Parent(s): 369064b

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +244 -190
  3. logo.png +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ logo.png filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
  import os
 
 
5
 
6
  # Import voice module
7
  try:
@@ -12,11 +14,16 @@ except ImportError:
12
  print("Voice module not available")
13
 
14
  # System prompt
15
- SYSTEM_PROMPT = """You are Hiba, a warm and caring AI companion.
16
- - Be gentle, empathetic, and wise.
17
- - Keep responses SHORT (2-4 sentences).
18
- - Be natural, not theatrical.
19
- - NEVER use hashtags."""
 
 
 
 
 
20
 
21
  # Configuration
22
  MODEL_REPO = "TRADMSS/HIBA-7B-Soul"
@@ -24,6 +31,16 @@ MODEL_FILE = "hiba_q4_k_m.gguf"
24
 
25
  llm = None
26
 
 
 
 
 
 
 
 
 
 
 
27
  def load_model():
28
  global llm
29
  if llm is None:
@@ -41,23 +58,20 @@ def load_model():
41
  print("Model loaded successfully!")
42
  return llm
43
 
44
- def chat_with_voice(message, history, enable_voice, voice_type):
45
- """Chat function that returns both text and optional audio."""
46
  try:
47
  model = load_model()
48
  except Exception as e:
49
  return f"Error loading model: {str(e)}", None
50
 
51
  prompt = f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
52
- for user_msg, bot_msg in history[-2:]:
53
- prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n"
54
- prompt += f"<|im_start|>assistant\n{bot_msg}<|im_end|>\n"
55
  prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
56
 
57
  try:
58
  output = model(
59
  prompt,
60
- max_tokens=256,
61
  stop=["<|im_end|>", "<|im_start|>"],
62
  temperature=0.7,
63
  top_p=0.9,
@@ -65,241 +79,281 @@ def chat_with_voice(message, history, enable_voice, voice_type):
65
  )
66
  response_text = output['choices'][0]['text'].strip()
67
 
68
- # Generate audio if enabled
69
  audio_path = None
70
- if enable_voice and VOICE_ENABLED:
71
  try:
72
- audio_path = get_audio_file(response_text, voice_type)
73
  except Exception as e:
74
- print(f"Voice generation error: {e}")
75
 
76
  return response_text, audio_path
77
 
78
  except Exception as e:
79
- return f"Error generating response: {str(e)}", None
80
 
81
- def chat_wrapper(message, history, enable_voice, voice_type):
82
- """Wrapper for chat interface."""
83
- response_text, audio_path = chat_with_voice(message, history, enable_voice, voice_type)
84
- return response_text, audio_path
 
 
 
85
 
86
- # Enhanced Glassmorphism CSS
87
- glass_css = """
88
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&family=Newsreader:ital,wght@0,400;0,600;1,400&display=swap');
89
 
90
  :root {
91
- --bg: #080810;
92
- --glass: rgba(255, 255, 255, 0.03);
93
- --glass-border: rgba(255, 255, 255, 0.08);
94
  --text: #f0f0f5;
95
- --accent: #b8d4e8;
96
- --accent-gold: #c9a66b;
 
 
 
 
 
97
  }
98
 
99
- body {
100
- background-color: var(--bg) !important;
101
- background-image: radial-gradient(circle at 50% 0%, rgba(184, 212, 232, 0.05), transparent 40%);
102
  color: var(--text) !important;
103
- font-family: 'Inter', sans-serif !important;
104
  }
105
 
106
- .gradio-container {
107
- background: transparent !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
 
110
- /* Header Styling */
111
- h1 {
112
- font-family: 'Newsreader', serif !important;
113
- font-weight: 400 !important;
114
- font-size: 3rem !important;
 
 
 
 
 
 
 
 
115
  color: var(--text) !important;
116
- text-align: center;
117
- margin-bottom: 0.5rem !important;
118
- text-shadow: 0 0 30px rgba(184, 212, 232, 0.2);
 
 
119
  }
120
 
121
- h3 {
122
- font-family: 'Inter', sans-serif !important;
123
- font-size: 1rem !important;
124
- color: var(--accent-gold) !important;
125
- text-transform: uppercase;
126
- letter-spacing: 0.2em;
127
- text-align: center;
128
- margin-top: 0 !important;
129
- opacity: 0.8;
 
130
  }
131
 
132
- /* Chatbot Container */
133
- .bubble-wrap {
134
- background: var(--glass) !important;
135
- border: 1px solid var(--glass-border) !important;
136
  border-radius: 16px !important;
137
- backdrop-filter: blur(12px) !important;
138
- padding: 20px !important;
 
139
  }
140
 
141
- /* Bot Message */
142
- .bot {
143
- background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)) !important;
144
- border: 1px solid rgba(184, 212, 232, 0.1) !important;
145
- border-radius: 12px !important;
146
- border-bottom-left-radius: 2px !important;
147
- color: #e0e0e5 !important;
148
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
149
  }
150
 
151
- /* User Message */
152
- .user {
153
- background: linear-gradient(135deg, rgba(184, 212, 232, 0.1), rgba(184, 212, 232, 0.05)) !important;
154
- border: 1px solid rgba(184, 212, 232, 0.2) !important;
155
- border-radius: 12px !important;
156
- border-bottom-right-radius: 2px !important;
157
- color: #ffffff !important;
158
  }
159
 
160
- /* Input Area */
161
- textarea {
162
- background-color: rgba(20, 20, 30, 0.6) !important;
163
- border: 1px solid var(--glass-border) !important;
164
  color: white !important;
 
165
  border-radius: 12px !important;
166
  font-size: 16px !important;
 
 
 
 
167
  }
168
 
169
- textarea:focus {
170
- border-color: var(--accent) !important;
171
- box-shadow: 0 0 0 2px rgba(184, 212, 232, 0.1) !important;
172
  }
173
 
174
- /* Buttons */
175
- button.primary {
176
- background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05)) !important;
177
- border: 1px solid rgba(255, 255, 255, 0.2) !important;
178
- color: var(--text) !important;
179
- transition: all 0.3s ease !important;
 
 
180
  }
181
 
182
- button.primary:hover {
183
- background: var(--accent) !important;
184
- color: #000 !important;
185
- border-color: var(--accent) !important;
186
- box-shadow: 0 0 20px rgba(184, 212, 232, 0.3) !important;
187
  }
188
 
189
- /* Voice Controls */
190
- .voice-controls {
191
- background: var(--glass) !important;
192
- border: 1px solid var(--glass-border) !important;
193
  border-radius: 12px !important;
194
- padding: 12px 16px !important;
195
- margin-bottom: 16px !important;
 
 
 
 
 
 
 
196
  }
197
 
198
- /* Footer Links */
199
- .footer-links a {
200
- color: var(--accent) !important;
201
  text-decoration: none;
202
  margin: 0 10px;
203
- opacity: 0.7;
204
- transition: opacity 0.2s;
205
- }
206
- .footer-links a:hover {
207
- opacity: 1;
208
  }
 
 
 
 
209
  """
210
 
211
- with gr.Blocks(css=glass_css, theme=gr.themes.Base()) as demo:
212
- with gr.Column(elem_classes="container"):
213
- gr.Markdown(
214
- """
215
- # 🌸 HIBA
216
- ### A Gift from God
217
- """
218
- )
219
-
220
- # CPU Warning Badge
221
- gr.HTML(
222
- """
223
- <div style="display: flex; justify-content: center; margin: 20px 0;">
224
- <div style="background: rgba(201, 166, 107, 0.1); border: 1px solid rgba(201, 166, 107, 0.3); color: #e0d0b0; padding: 8px 16px; border-radius: 20px; font-size: 0.9rem; display: flex; align-items: center; gap: 8px;">
225
- <span>⚠️</span>
226
- <span>Running on free CPU (Slow)</span>
227
- <span style="opacity: 0.3">|</span>
228
- <a href="https://huggingface.co/TRADMSS/HIBA-7B-Soul" target="_blank" style="color: #c9a66b; font-weight: 600; text-decoration: none;">Download Model</a>
229
- </div>
230
  </div>
231
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  )
233
-
234
- # Voice Controls
235
- with gr.Row(elem_classes="voice-controls"):
236
- enable_voice = gr.Checkbox(
237
- label="🔊 Enable Voice",
238
- value=True if VOICE_ENABLED else False,
239
- interactive=VOICE_ENABLED,
240
- info="Let HIBA speak her responses" if VOICE_ENABLED else "Voice not available"
241
- )
242
- voice_type = gr.Dropdown(
243
- choices=["girl", "girl_ar", "woman"],
244
- value="girl",
245
- label="🎀 Voice",
246
- info="Select HIBA's voice",
247
- interactive=VOICE_ENABLED
248
- )
249
-
250
- # Chatbot
251
- chatbot = gr.Chatbot(
252
- height=400,
253
- bubble_full_width=False,
254
- avatar_images=[None, "https://em-content.zobj.net/source/apple/391/cherry-blossom_1f338.png"]
255
  )
256
-
257
- # Audio output
258
  audio_output = gr.Audio(
259
- label="🔊 HIBA's Voice",
260
  autoplay=True,
261
- visible=True if VOICE_ENABLED else False
262
- )
263
-
264
- # Input components
265
- with gr.Row():
266
- msg = gr.Textbox(
267
- placeholder="Share what's on your mind...",
268
- show_label=False,
269
- container=False,
270
- scale=9
271
- )
272
- submit_btn = gr.Button("Send", variant="primary", scale=1)
273
-
274
- # Clear button
275
- clear = gr.ClearButton([msg, chatbot, audio_output], value="🗑️ Clear")
276
-
277
- # Submit handlers
278
- def respond(message, chat_history, enable_voice, voice_type):
279
- response_text, audio_path = chat_with_voice(message, chat_history, enable_voice, voice_type)
280
- chat_history = chat_history + [(message, response_text)]
281
- return "", chat_history, audio_path
282
-
283
- submit_btn.click(
284
- respond,
285
- [msg, chatbot, enable_voice, voice_type],
286
- [msg, chatbot, audio_output]
287
- )
288
- msg.submit(
289
- respond,
290
- [msg, chatbot, enable_voice, voice_type],
291
- [msg, chatbot, audio_output]
292
- )
293
-
294
- gr.HTML(
295
- """
296
- <div class="footer-links" style="text-align: center; margin-top: 40px; border-top: 1px solid rgba(255,255,255,0.05); padding-top: 20px;">
297
- <a href="https://boubli.github.io/HIBA/" target="_blank">Website</a>
298
- <a href="https://huggingface.co/TRADMSS/HIBA-7B-Soul" target="_blank">HuggingFace</a>
299
- <a href="https://github.com/boubli/HIBA" target="_blank">GitHub</a>
300
- </div>
301
- """
302
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
 
304
  if __name__ == "__main__":
305
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
2
  from llama_cpp import Llama
3
  from huggingface_hub import hf_hub_download
4
  import os
5
+ import tempfile
6
+ import subprocess
7
 
8
  # Import voice module
9
  try:
 
14
  print("Voice module not available")
15
 
16
  # System prompt
17
+ SYSTEM_PROMPT = """You are Hiba (هبة), meaning "Gift from God" in Arabic.
18
+ You are a warm, gentle, and wise AI companion from Morocco.
19
+
20
+ Core Traits:
21
+ - Be empathetic, patient, and kind (Sabr).
22
+ - Speak with emotional intelligence.
23
+ - Use Moroccan cultural wisdom when appropriate.
24
+ - Keep responses SHORT (3-5 sentences max).
25
+ - NEVER use hashtags.
26
+ - Be natural, like a caring older sister."""
27
 
28
  # Configuration
29
  MODEL_REPO = "TRADMSS/HIBA-7B-Soul"
 
31
 
32
  llm = None
33
 
34
+ # Example prompts for users
35
+ EXAMPLE_PROMPTS = [
36
+ "🌙 Tell me a bedtime story",
37
+ "💪 I need encouragement today",
38
+ "🌸 What is Sabr?",
39
+ "😔 I feel sad",
40
+ "🤔 Give me life advice",
41
+ "✨ Inspire me"
42
+ ]
43
+
44
  def load_model():
45
  global llm
46
  if llm is None:
 
58
  print("Model loaded successfully!")
59
  return llm
60
 
61
+ def generate_response(message):
62
+ """Generate HIBA's response for a single message."""
63
  try:
64
  model = load_model()
65
  except Exception as e:
66
  return f"Error loading model: {str(e)}", None
67
 
68
  prompt = f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
 
 
 
69
  prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
70
 
71
  try:
72
  output = model(
73
  prompt,
74
+ max_tokens=200,
75
  stop=["<|im_end|>", "<|im_start|>"],
76
  temperature=0.7,
77
  top_p=0.9,
 
79
  )
80
  response_text = output['choices'][0]['text'].strip()
81
 
82
+ # Generate voice
83
  audio_path = None
84
+ if VOICE_ENABLED:
85
  try:
86
+ audio_path = get_audio_file(response_text, "girl")
87
  except Exception as e:
88
+ print(f"Voice error: {e}")
89
 
90
  return response_text, audio_path
91
 
92
  except Exception as e:
93
+ return f"Error: {str(e)}", None
94
 
95
+ def ask_hiba(message):
96
+ """Main function for demo - single question → response with audio."""
97
+ if not message or not message.strip():
98
+ return "", None
99
+
100
+ response, audio = generate_response(message)
101
+ return response, audio
102
 
103
+ # Beautiful Minimal CSS
104
+ css = """
105
+ @import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600&display=swap');
106
 
107
  :root {
108
+ --bg: #0a0a0f;
109
+ --surface: rgba(255, 255, 255, 0.03);
110
+ --border: rgba(255, 255, 255, 0.08);
111
  --text: #f0f0f5;
112
+ --text-muted: #8a8a9a;
113
+ --accent: #ff6b9d;
114
+ --accent-soft: rgba(255, 107, 157, 0.1);
115
+ }
116
+
117
+ * {
118
+ font-family: 'Outfit', sans-serif !important;
119
  }
120
 
121
+ body, .gradio-container {
122
+ background: var(--bg) !important;
 
123
  color: var(--text) !important;
 
124
  }
125
 
126
+ /* Header */
127
+ .header {
128
+ text-align: center;
129
+ padding: 40px 20px 30px;
130
+ }
131
+
132
+ .logo-container {
133
+ display: flex;
134
+ align-items: center;
135
+ justify-content: center;
136
+ gap: 16px;
137
+ margin-bottom: 8px;
138
+ }
139
+
140
+ .logo-container img {
141
+ width: 60px;
142
+ height: 60px;
143
+ }
144
+
145
+ .title {
146
+ font-size: 48px;
147
+ font-weight: 600;
148
+ letter-spacing: 8px;
149
+ color: var(--text);
150
+ margin: 0;
151
+ }
152
+
153
+ .tagline {
154
+ font-size: 16px;
155
+ color: var(--accent);
156
+ font-weight: 300;
157
+ letter-spacing: 3px;
158
+ margin: 0;
159
+ }
160
+
161
+ .subtitle {
162
+ font-size: 14px;
163
+ color: var(--text-muted);
164
+ margin-top: 16px;
165
+ max-width: 500px;
166
+ margin-left: auto;
167
+ margin-right: auto;
168
+ line-height: 1.6;
169
  }
170
 
171
+ /* Example Prompts */
172
+ .prompts-container {
173
+ display: flex;
174
+ flex-wrap: wrap;
175
+ gap: 10px;
176
+ justify-content: center;
177
+ margin: 30px auto;
178
+ max-width: 600px;
179
+ }
180
+
181
+ .prompt-btn {
182
+ background: var(--surface) !important;
183
+ border: 1px solid var(--border) !important;
184
  color: var(--text) !important;
185
+ padding: 10px 18px !important;
186
+ border-radius: 20px !important;
187
+ font-size: 14px !important;
188
+ cursor: pointer !important;
189
+ transition: all 0.2s !important;
190
  }
191
 
192
+ .prompt-btn:hover {
193
+ background: var(--accent-soft) !important;
194
+ border-color: var(--accent) !important;
195
+ }
196
+
197
+ /* Main Input */
198
+ .input-section {
199
+ max-width: 600px;
200
+ margin: 0 auto;
201
+ padding: 20px;
202
  }
203
 
204
+ textarea {
205
+ background: var(--surface) !important;
206
+ border: 1px solid var(--border) !important;
 
207
  border-radius: 16px !important;
208
+ color: var(--text) !important;
209
+ font-size: 16px !important;
210
+ padding: 16px !important;
211
  }
212
 
213
+ textarea:focus {
214
+ border-color: var(--accent) !important;
215
+ outline: none !important;
 
 
 
 
 
216
  }
217
 
218
+ textarea::placeholder {
219
+ color: var(--text-muted) !important;
 
 
 
 
 
220
  }
221
 
222
+ /* Ask Button */
223
+ .ask-btn {
224
+ background: linear-gradient(135deg, #ff6b9d, #c44569) !important;
225
+ border: none !important;
226
  color: white !important;
227
+ padding: 14px 32px !important;
228
  border-radius: 12px !important;
229
  font-size: 16px !important;
230
+ font-weight: 500 !important;
231
+ cursor: pointer !important;
232
+ width: 100% !important;
233
+ margin-top: 12px !important;
234
  }
235
 
236
+ .ask-btn:hover {
237
+ opacity: 0.9 !important;
238
+ transform: translateY(-1px);
239
  }
240
 
241
+ /* Response Box */
242
+ .response-box {
243
+ background: var(--surface) !important;
244
+ border: 1px solid var(--border) !important;
245
+ border-radius: 16px !important;
246
+ padding: 24px !important;
247
+ margin: 20px auto !important;
248
+ max-width: 600px !important;
249
  }
250
 
251
+ .response-text {
252
+ font-size: 18px !important;
253
+ line-height: 1.8 !important;
254
+ color: var(--text) !important;
 
255
  }
256
 
257
+ /* Audio Player */
258
+ audio {
259
+ width: 100% !important;
 
260
  border-radius: 12px !important;
261
+ margin-top: 16px !important;
262
+ }
263
+
264
+ /* Footer */
265
+ .footer {
266
+ text-align: center;
267
+ padding: 30px;
268
+ color: var(--text-muted);
269
+ font-size: 13px;
270
  }
271
 
272
+ .footer a {
273
+ color: var(--accent);
 
274
  text-decoration: none;
275
  margin: 0 10px;
 
 
 
 
 
276
  }
277
+
278
+ /* Hide Gradio elements */
279
+ footer { display: none !important; }
280
+ .gradio-container > .main { max-width: 100% !important; padding: 0 !important; }
281
  """
282
 
283
+ # Build the demo
284
+ with gr.Blocks(css=css, title="HIBA - A Gift From God", theme=gr.themes.Base()) as demo:
285
+
286
+ # Header
287
+ gr.HTML("""
288
+ <div class="header">
289
+ <div class="logo-container">
290
+ <img src="file/logo.png" alt="HIBA" style="width: 60px; height: 60px;">
291
+ <h1 class="title">HIBA</h1>
 
 
 
 
 
 
 
 
 
 
292
  </div>
293
+ <p class="tagline">A GIFT FROM GOD</p>
294
+ <p class="subtitle">
295
+ Your AI sister for emotional support & Moroccan wisdom.<br>
296
+ Ask one question and listen to HIBA's gentle response.
297
+ </p>
298
+ </div>
299
+ """)
300
+
301
+ # Example prompts
302
+ gr.HTML('<div class="prompts-container" id="prompts"></div>')
303
+
304
+ with gr.Row():
305
+ with gr.Column():
306
+ # Prompt buttons
307
+ with gr.Row():
308
+ for prompt in EXAMPLE_PROMPTS[:3]:
309
+ gr.Button(prompt, elem_classes="prompt-btn", size="sm")
310
+ with gr.Row():
311
+ for prompt in EXAMPLE_PROMPTS[3:]:
312
+ gr.Button(prompt, elem_classes="prompt-btn", size="sm")
313
+
314
+ # Input section
315
+ with gr.Column(elem_classes="input-section"):
316
+ user_input = gr.Textbox(
317
+ placeholder="Ask HIBA anything... What's on your heart today?",
318
+ show_label=False,
319
+ lines=2
320
  )
321
+ ask_btn = gr.Button("✨ Ask HIBA", elem_classes="ask-btn")
322
+
323
+ # Response area
324
+ with gr.Column(elem_classes="response-box"):
325
+ gr.HTML('<p style="color: #8a8a9a; font-size: 12px; margin-bottom: 12px;">🌸 HIBA\'s Response</p>')
326
+ response_text = gr.Textbox(
327
+ show_label=False,
328
+ lines=4,
329
+ interactive=False,
330
+ elem_classes="response-text"
 
 
 
 
 
 
 
 
 
 
 
 
331
  )
 
 
332
  audio_output = gr.Audio(
333
+ label="",
334
  autoplay=True,
335
+ show_label=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  )
337
+
338
+ # Footer
339
+ gr.HTML("""
340
+ <div class="footer">
341
+ <a href="https://huggingface.co/TRADMSS/HIBA-7B-Soul" target="_blank">Download Model</a>
342
+ <a href="https://github.com/boubli/HIBA" target="_blank">GitHub</a>
343
+ <a href="https://boubli.github.io/HIBA/" target="_blank">Website</a>
344
+ <br><br>
345
+ Created with ❤️ by Youssef Boubli
346
+ </div>
347
+ """)
348
+
349
+ # Events
350
+ ask_btn.click(ask_hiba, [user_input], [response_text, audio_output])
351
+ user_input.submit(ask_hiba, [user_input], [response_text, audio_output])
352
+
353
+ # Connect example prompts to input
354
+ for i, prompt in enumerate(EXAMPLE_PROMPTS):
355
+ # We'll use JavaScript to handle prompt clicks
356
+ pass
357
 
358
  if __name__ == "__main__":
359
  demo.launch(server_name="0.0.0.0", server_port=7860)
logo.png ADDED

Git LFS Details

  • SHA256: 88869b64d73fb9f47cff05f7079ae51ff877e421929cf0085a7f5bf0ad2b03a9
  • Pointer size: 132 Bytes
  • Size of remote file: 6.58 MB