Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
|
5 |
-
|
6 |
-
|
7 |
-
def print_like_dislike(x: gr.LikeData):
|
8 |
-
print(x.index, x.value, x.liked)
|
9 |
-
|
10 |
-
|
11 |
-
def add_message(history, message):
|
12 |
-
for x in message["files"]:
|
13 |
-
history.append({"role": "user", "content": {"path": x}})
|
14 |
-
if message["text"] is not None:
|
15 |
-
history.append({"role": "user", "content": message["text"]})
|
16 |
-
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
17 |
-
|
18 |
-
|
19 |
-
def bot(history: list):
|
20 |
-
response = "**That's cool!**"
|
21 |
-
history.append({"role": "assistant", "content": ""})
|
22 |
-
for character in response:
|
23 |
-
history[-1]["content"] += character
|
24 |
-
time.sleep(0.05)
|
25 |
-
yield history
|
26 |
|
|
|
|
|
|
|
|
|
27 |
|
28 |
with gr.Blocks() as demo:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
interactive=True,
|
33 |
-
file_count="multiple",
|
34 |
-
placeholder="Enter message or upload file...",
|
35 |
-
show_label=False,
|
36 |
-
)
|
37 |
-
|
38 |
-
chat_msg = chat_input.submit(
|
39 |
-
add_message, [chatbot, chat_input], [chatbot, chat_input]
|
40 |
-
)
|
41 |
-
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
|
42 |
-
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
|
43 |
|
44 |
-
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import argparse
|
3 |
+
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
parser = argparse.ArgumentParser()
|
6 |
+
parser.add_argument("--name", type=str, default="User")
|
7 |
+
args, unknown = parser.parse_known_args()
|
8 |
+
print(sys.argv)
|
9 |
|
10 |
with gr.Blocks() as demo:
|
11 |
+
gr.Markdown(f"# Greetings {args.name}!")
|
12 |
+
inp = gr.Textbox()
|
13 |
+
out = gr.Textbox()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
inp.change(fn=lambda x: x, inputs=inp, outputs=out)
|
16 |
|
17 |
if __name__ == "__main__":
|
18 |
+
demo.launch(auth=("admin", "admin"))
|