1nabeelsiddiqui commited on
Commit
61e4e3c
·
verified ·
1 Parent(s): 576812d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
app.py CHANGED
@@ -6,6 +6,20 @@ For more information on `huggingface_hub` Inference API support, please check th
6
  """
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def respond(
11
  message,
@@ -43,21 +57,24 @@ def respond(
43
  """
44
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
  """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
- )
 
 
 
61
 
62
 
63
  if __name__ == "__main__":
 
6
  """
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
+ def add_message(history, message):
10
+ for x in message["files"]:
11
+ history.append({"role": "user", "content": {"path": x}})
12
+ if message["text"] is not None:
13
+ history.append({"role": "user", "content": message["text"]})
14
+ return history, gr.MultimodalTextbox(value=None, interactive=False)
15
+
16
+ def bot(history: list):
17
+ response = "**That's cool!**"
18
+ history.append({"role": "assistant", "content": ""})
19
+ for character in response:
20
+ history[-1]["content"] += character
21
+ time.sleep(0.05)
22
+ yield history
23
 
24
  def respond(
25
  message,
 
57
  """
58
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
59
  """
60
+ with gr.blocks() as demo:
61
+ chatbot = gr.Chatbot(elem_id="chatbot", bubble_full_width=False, type="messages")
62
+
63
+ chat_input = gr.MultimodalTextbox(
64
+ interactive=True,
65
+ file_count="multiple",
66
+ placeholder="Enter message or upload file...",
67
+ show_label=False,
68
+ sources=["upload"],
69
+ )
70
+
71
+ chat_msg = chat_input.submit(
72
+ add_message, [chatbot, chat_input], [chatbot, chat_input]
73
+ )
74
+ bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
75
+ bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
76
+
77
+ chatbot.like(print_like_dislike, None, None, like_user_message=True)
78
 
79
 
80
  if __name__ == "__main__":