freddyaboulton HF Staff commited on
Commit
ccb17a9
·
verified ·
1 Parent(s): d1b25e9

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. run.ipynb +1 -1
  3. run.py +4 -5
README.md CHANGED
@@ -5,7 +5,7 @@ emoji: 🔥
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
- sdk_version: 5.49.1
9
  app_file: run.py
10
  pinned: false
11
  hf_oauth: true
 
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 6.0.0
9
  app_file: run.py
10
  pinned: false
11
  hf_oauth: true
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_retry_undo_like"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio huggingface_hub "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["from huggingface_hub import InferenceClient\n", "import gradio as gr\n", "\n", "client = InferenceClient()\n", "\n", "def respond(\n", " prompt: str,\n", " history,\n", "):\n", " if not history:\n", " history = [{\"role\": \"system\", \"content\": \"You are a friendly chatbot\"}]\n", " history.append({\"role\": \"user\", \"content\": prompt})\n", "\n", " yield history\n", "\n", " response = {\"role\": \"assistant\", \"content\": \"\"}\n", " for message in client.chat_completion( # type: ignore\n", " history,\n", " temperature=0.95,\n", " top_p=0.9,\n", " max_tokens=512,\n", " stream=True,\n", " model=\"HuggingFaceH4/zephyr-7b-beta\"\n", " ):\n", " response[\"content\"] += message.choices[0].delta.content or \"\" if message.choices else \"\"\n", " yield history + [response]\n", "\n", "\n", "def handle_undo(history, undo_data: gr.UndoData):\n", " return history[:undo_data.index], history[undo_data.index]['content']\n", "\n", "def handle_retry(history, retry_data: gr.RetryData):\n", " new_history = history[:retry_data.index]\n", " previous_prompt = history[retry_data.index]['content']\n", " yield from respond(previous_prompt, new_history)\n", "\n", "\n", "def handle_like(data: gr.LikeData):\n", " if data.liked:\n", " print(\"You upvoted this response: \", data.value)\n", " else:\n", " print(\"You downvoted this response: \", data.value)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"# Chat with Hugging Face Zephyr 7b \ud83e\udd17\")\n", " chatbot = gr.Chatbot(\n", " label=\"Agent\",\n", " type=\"messages\",\n", " avatar_images=(\n", " None,\n", " \"https://em-content.zobj.net/source/twitter/376/hugging-face_1f917.png\",\n", " ),\n", " )\n", " prompt = gr.Textbox(max_lines=1, label=\"Chat Message\")\n", " prompt.submit(respond, [prompt, chatbot], [chatbot])\n", " prompt.submit(lambda: \"\", None, [prompt])\n", " chatbot.undo(handle_undo, chatbot, [chatbot, prompt])\n", " chatbot.retry(handle_retry, chatbot, [chatbot])\n", " chatbot.like(handle_like, None, None)\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_retry_undo_like"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio huggingface_hub "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["from huggingface_hub import InferenceClient\n", "import gradio as gr\n", "\n", "client = InferenceClient()\n", "\n", "def respond(\n", " prompt: str,\n", " history,\n", "):\n", " if not history:\n", " history = [{\"role\": \"system\", \"content\": \"You are a friendly chatbot\"}]\n", " history.append({\"role\": \"user\", \"content\": prompt})\n", "\n", " yield history\n", "\n", " response = {\"role\": \"assistant\", \"content\": \"\"}\n", " for message in client.chat_completion( # type: ignore\n", " history,\n", " temperature=0.95,\n", " top_p=0.9,\n", " max_tokens=512,\n", " stream=True,\n", " model=\"openai/gpt-oss-20b\"\n", " ):\n", " response[\"content\"] += message.choices[0].delta.content or \"\" if message.choices else \"\"\n", " yield history + [response]\n", "\n", "\n", "def handle_undo(history, undo_data: gr.UndoData):\n", " return history[:undo_data.index], history[undo_data.index]['content'][0][\"text\"]\n", "\n", "def handle_retry(history, retry_data: gr.RetryData):\n", " new_history = history[:retry_data.index]\n", " previous_prompt = history[retry_data.index]['content'][0][\"text\"]\n", " yield from respond(previous_prompt, new_history)\n", "\n", "\n", "def handle_like(data: gr.LikeData):\n", " if data.liked:\n", " print(\"You upvoted this response: \", data.value)\n", " else:\n", " print(\"You downvoted this response: \", data.value)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"# Chat with GPT-OSS 20b \ud83e\udd17\")\n", " chatbot = gr.Chatbot(\n", " label=\"Agent\",\n", " avatar_images=(\n", " None,\n", " \"https://em-content.zobj.net/source/twitter/376/hugging-face_1f917.png\",\n", " ),\n", " )\n", " prompt = gr.Textbox(max_lines=1, label=\"Chat Message\")\n", " prompt.submit(respond, [prompt, chatbot], [chatbot])\n", " prompt.submit(lambda: \"\", None, [prompt])\n", " chatbot.undo(handle_undo, chatbot, [chatbot, prompt])\n", " chatbot.retry(handle_retry, chatbot, [chatbot])\n", " chatbot.like(handle_like, None, None)\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -20,18 +20,18 @@ def respond(
20
  top_p=0.9,
21
  max_tokens=512,
22
  stream=True,
23
- model="HuggingFaceH4/zephyr-7b-beta"
24
  ):
25
  response["content"] += message.choices[0].delta.content or "" if message.choices else ""
26
  yield history + [response]
27
 
28
 
29
  def handle_undo(history, undo_data: gr.UndoData):
30
- return history[:undo_data.index], history[undo_data.index]['content']
31
 
32
  def handle_retry(history, retry_data: gr.RetryData):
33
  new_history = history[:retry_data.index]
34
- previous_prompt = history[retry_data.index]['content']
35
  yield from respond(previous_prompt, new_history)
36
 
37
 
@@ -43,10 +43,9 @@ def handle_like(data: gr.LikeData):
43
 
44
 
45
  with gr.Blocks() as demo:
46
- gr.Markdown("# Chat with Hugging Face Zephyr 7b 🤗")
47
  chatbot = gr.Chatbot(
48
  label="Agent",
49
- type="messages",
50
  avatar_images=(
51
  None,
52
  "https://em-content.zobj.net/source/twitter/376/hugging-face_1f917.png",
 
20
  top_p=0.9,
21
  max_tokens=512,
22
  stream=True,
23
+ model="openai/gpt-oss-20b"
24
  ):
25
  response["content"] += message.choices[0].delta.content or "" if message.choices else ""
26
  yield history + [response]
27
 
28
 
29
  def handle_undo(history, undo_data: gr.UndoData):
30
+ return history[:undo_data.index], history[undo_data.index]['content'][0]["text"]
31
 
32
  def handle_retry(history, retry_data: gr.RetryData):
33
  new_history = history[:retry_data.index]
34
+ previous_prompt = history[retry_data.index]['content'][0]["text"]
35
  yield from respond(previous_prompt, new_history)
36
 
37
 
 
43
 
44
 
45
  with gr.Blocks() as demo:
46
+ gr.Markdown("# Chat with GPT-OSS 20b 🤗")
47
  chatbot = gr.Chatbot(
48
  label="Agent",
 
49
  avatar_images=(
50
  None,
51
  "https://em-content.zobj.net/source/twitter/376/hugging-face_1f917.png",