freddyaboulton HF Staff commited on
Commit
d9c038a
·
verified ·
1 Parent(s): 95608fc

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +7 -7
  2. run.ipynb +1 -0
  3. run.py +36 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Chatinterface Deep Link
3
- emoji: 🦀
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.39.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: chatinterface_deep_link
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 5.39.0
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatinterface_deep_link"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import time\n", "import gradio as gr\n", "\n", "def slow_echo(message, history):\n", " for i in range(len(message[\"text\"])):\n", " time.sleep(0.05)\n", " yield \"You typed: \" + message[\"text\"][: i + 1]\n", "\n", "chat = gr.ChatInterface(\n", " slow_echo,\n", " type=\"messages\",\n", " flagging_mode=\"manual\",\n", " flagging_options=[\"Like\", \"Spam\", \"Inappropriate\", \"Other\"],\n", " save_history=False,\n", " multimodal=True,\n", ")\n", "\n", "with gr.Blocks() as demo:\n", "\n", " chat.render()\n", " gr.DeepLinkButton()\n", "\n", "with demo.route(\"cached_examples\"):\n", " gr.Interface(lambda x, y: f\"{y}: {x}\",\n", " inputs=[gr.Textbox(label=\"name\"),\n", " gr.Radio(label=\"Salutation\", choices=[\"Hello\", \"Greetings\"])\n", " ],\n", " outputs=gr.Textbox(label=\"Output\"),\n", " examples=[[\"Freddy\", \"Hello\"]],\n", " cache_examples=True,\n", " deep_link=True)\n", "\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import gradio as gr
3
+
4
+ def slow_echo(message, history):
5
+ for i in range(len(message["text"])):
6
+ time.sleep(0.05)
7
+ yield "You typed: " + message["text"][: i + 1]
8
+
9
+ chat = gr.ChatInterface(
10
+ slow_echo,
11
+ type="messages",
12
+ flagging_mode="manual",
13
+ flagging_options=["Like", "Spam", "Inappropriate", "Other"],
14
+ save_history=False,
15
+ multimodal=True,
16
+ )
17
+
18
+ with gr.Blocks() as demo:
19
+
20
+ chat.render()
21
+ gr.DeepLinkButton()
22
+
23
+ with demo.route("cached_examples"):
24
+ gr.Interface(lambda x, y: f"{y}: {x}",
25
+ inputs=[gr.Textbox(label="name"),
26
+ gr.Radio(label="Salutation", choices=["Hello", "Greetings"])
27
+ ],
28
+ outputs=gr.Textbox(label="Output"),
29
+ examples=[["Freddy", "Hello"]],
30
+ cache_examples=True,
31
+ deep_link=True)
32
+
33
+
34
+
35
+ if __name__ == "__main__":
36
+ demo.launch()