zizo66 commited on
Commit
f25bc2b
·
verified ·
1 Parent(s): da7db39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # تحميل النموذج من Hugging Face
5
  client = InferenceClient("meta-llama/Llama-2-7b-chat-hf")
6
 
7
- # قائمة السيناريوهات
8
  scenarios = {
9
  "restaurant": "You are in a restaurant. Help the user order food in English.",
10
  "airport": "You are at an airport. Help the user check in and find their gate.",
@@ -16,10 +16,10 @@ scenarios = {
16
  def scenario_prompt(choice):
17
  return scenarios.get(choice, "You are a language tutor AI. Help users practice real-life conversations.")
18
 
19
- # دالة لمعالجة المحادثة
20
  def respond(
21
  message,
22
- history: list[tuple[str, str]],
23
  system_message,
24
  max_tokens,
25
  temperature,
@@ -27,11 +27,9 @@ def respond(
27
  ):
28
  messages = [{"role": "system", "content": system_message}]
29
 
 
30
  for val in history:
31
- if val[0]:
32
- messages.append({"role": "user", "content": val[0]})
33
- if val[1]:
34
- messages.append({"role": "assistant", "content": val[1]})
35
 
36
  messages.append({"role": "user", "content": message})
37
 
@@ -48,9 +46,10 @@ def respond(
48
  response += token
49
  yield response
50
 
51
- # واجهة Gradio للمحادثة
52
  demo = gr.ChatInterface(
53
  respond,
 
54
  additional_inputs=[
55
  gr.Dropdown(choices=list(scenarios.keys()), label="Choose a scenario", value="restaurant"),
56
  gr.Textbox(value=scenario_prompt("restaurant"), label="System message"),
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # تحميل نموذج LLaMA من Hugging Face
5
  client = InferenceClient("meta-llama/Llama-2-7b-chat-hf")
6
 
7
+ # قائمة السيناريوهات المتاحة
8
  scenarios = {
9
  "restaurant": "You are in a restaurant. Help the user order food in English.",
10
  "airport": "You are at an airport. Help the user check in and find their gate.",
 
16
  def scenario_prompt(choice):
17
  return scenarios.get(choice, "You are a language tutor AI. Help users practice real-life conversations.")
18
 
19
+ # دالة للمحادثة مع الذكاء الاصطناعي
20
  def respond(
21
  message,
22
+ history, # إزالة الـ Type Hint القديم لأن `Gradio` الآن يستخدم `messages`
23
  system_message,
24
  max_tokens,
25
  temperature,
 
27
  ):
28
  messages = [{"role": "system", "content": system_message}]
29
 
30
+ # استخدام الـ `messages` بدلاً من القائمة القديمة `tuples`
31
  for val in history:
32
+ messages.append(val) # بدلاً من تحويلها إلى `tuples`
 
 
 
33
 
34
  messages.append({"role": "user", "content": message})
35
 
 
46
  response += token
47
  yield response
48
 
49
+ # واجهة `Gradio` للتفاعل مع المستخدم
50
  demo = gr.ChatInterface(
51
  respond,
52
+ chatbot=gr.Chatbot(type="messages"), # إصلاح التحذير باستخدام `type="messages"`
53
  additional_inputs=[
54
  gr.Dropdown(choices=list(scenarios.keys()), label="Choose a scenario", value="restaurant"),
55
  gr.Textbox(value=scenario_prompt("restaurant"), label="System message"),