nevreal commited on
Commit
b806b63
·
verified ·
1 Parent(s): 508e792

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -12,11 +12,15 @@ client = InferenceClient(
12
  )
13
 
14
  # Function to handle chatbot response
15
- def chat_with_model(user_input, history):
16
  response = ""
 
 
 
 
17
  # Send user input to the model
18
  for message in client.chat_completion(
19
- messages=[{"role": "user", "content": user_input}],
20
  max_tokens=500,
21
  stream=True,
22
  ):
@@ -29,20 +33,25 @@ def chat_with_model(user_input, history):
29
  # Gradio interface
30
  with gr.Blocks(theme="nevreal/blues") as ui:
31
  gr.Markdown("# Gradio Chatbot with Phi-3-mini-4k-instruct")
32
-
 
 
 
 
 
 
 
33
  # User input and chatbot output
34
  chatbot = gr.Chatbot()
35
  with gr.Row():
36
-
37
  user_input = gr.Textbox(show_label=False, placeholder="Type a message...")
38
-
39
  send_button = gr.Button("Send")
40
 
41
  # Store the chat history
42
  history = gr.State([])
43
 
44
  # Send button action
45
- send_button.click(fn=chat_with_model, inputs=[user_input, history], outputs=[chatbot, history])
46
 
47
  # Launch the web UI
48
  ui.launch()
 
12
  )
13
 
14
  # Function to handle chatbot response
15
+ def chat_with_model(user_input, system_content, history):
16
  response = ""
17
+ # Prepare the conversation with system content
18
+ messages = [{"role": "system", "content": system_content},
19
+ {"role": "user", "content": user_input}]
20
+
21
  # Send user input to the model
22
  for message in client.chat_completion(
23
+ messages=messages,
24
  max_tokens=500,
25
  stream=True,
26
  ):
 
33
  # Gradio interface
34
  with gr.Blocks(theme="nevreal/blues") as ui:
35
  gr.Markdown("# Gradio Chatbot with Phi-3-mini-4k-instruct")
36
+
37
+ # Dropdown for system content
38
+ system_content = gr.Textbox(
39
+ label="System Instructions",
40
+ value=f"you are Phi-3-mini-4k-instruct assistant a friendly chatbot developed by Microsoft and created by [nevproject](https://huggingface.co/nevproject)",
41
+ visible=False
42
+ )
43
+
44
  # User input and chatbot output
45
  chatbot = gr.Chatbot()
46
  with gr.Row():
 
47
  user_input = gr.Textbox(show_label=False, placeholder="Type a message...")
 
48
  send_button = gr.Button("Send")
49
 
50
  # Store the chat history
51
  history = gr.State([])
52
 
53
  # Send button action
54
+ send_button.click(fn=chat_with_model, inputs=[user_input, system_content, history], outputs=[chatbot, history])
55
 
56
  # Launch the web UI
57
  ui.launch()