Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 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__":
|