waleedmohd commited on
Commit
8abd7cb
·
verified ·
1 Parent(s): 549f4f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -1,24 +1,24 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Use Arabic-optimized model (Free for commercial use)
5
- client = InferenceClient("aubmindlab/aragpt2-base") # Arabic GPT-2 model
6
 
7
  def respond(
8
- message,
9
- history: list[tuple[str, str]],
10
  system_message="أنت مساعد مفيد يتحدث العربية",
11
  max_tokens=512,
12
  temperature=0.7,
13
  top_p=0.95,
14
  ):
15
  # Force Arabic responses
16
- prompt = f"باللغة العربية: {message}"
17
 
 
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
- # Add conversation history
21
- for user_msg, bot_msg in history[-3:]: # Limit history for mobile performance
22
  if user_msg:
23
  messages.append({"role": "user", "content": user_msg})
24
  if bot_msg:
@@ -33,7 +33,7 @@ def respond(
33
  max_new_tokens=max_tokens,
34
  stream=True,
35
  temperature=temperature,
36
- repetition_penalty=1.2, # Reduce repetition common in Arabic dialects
37
  ):
38
  response += chunk
39
  yield response
@@ -58,9 +58,8 @@ demo = gr.ChatInterface(
58
  )
59
 
60
  if __name__ == "__main__":
61
- # Mobile optimization settings
62
  demo.launch(
63
- enable_queue=True,
64
- allowed_paths=["./assets"], # For local Arabic fonts if needed
65
- prevent_thread_lock=True
66
  )
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Use Arabic-optimized model
5
+ client = InferenceClient("aubmindlab/aragpt2-base")
6
 
7
  def respond(
8
+ message: str,
9
+ history: list[list[str]], # Updated format
10
  system_message="أنت مساعد مفيد يتحدث العربية",
11
  max_tokens=512,
12
  temperature=0.7,
13
  top_p=0.95,
14
  ):
15
  # Force Arabic responses
16
+ prompt = f"باللغة العربية: {message}"
17
 
18
+ # Format history in messages format
19
  messages = [{"role": "system", "content": system_message}]
20
 
21
+ for user_msg, bot_msg in history:
 
22
  if user_msg:
23
  messages.append({"role": "user", "content": user_msg})
24
  if bot_msg:
 
33
  max_new_tokens=max_tokens,
34
  stream=True,
35
  temperature=temperature,
36
+ repetition_penalty=1.2,
37
  ):
38
  response += chunk
39
  yield response
 
58
  )
59
 
60
  if __name__ == "__main__":
61
+ # Correct launch parameters
62
  demo.launch(
63
+ share=False, # Set to True for temporary public link
64
+ auth=("user", "pass") # Optional basic auth
 
65
  )