Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.13.0
|
| 8 |
-
app_file:
|
| 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_prefill
|
| 4 |
+
emoji: 🔥
|
| 5 |
+
colorFrom: indigo
|
| 6 |
+
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
sdk_version: 5.13.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_prefill"]}, {"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 gradio as gr\n", "import random\n", "\n", "def prefill_chatbot(choice):\n", " if choice == \"Greeting\":\n", " return [\n", " {\"role\": \"user\", \"content\": \"Hi there!\"},\n", " {\"role\": \"assistant\", \"content\": \"Hello! How can I assist you today?\"}\n", " ]\n", " elif choice == \"Complaint\":\n", " return [\n", " {\"role\": \"user\", \"content\": \"I'm not happy with the service.\"},\n", " {\"role\": \"assistant\", \"content\": \"I'm sorry to hear that. Can you please tell me more about the issue?\"}\n", " ]\n", " else:\n", " return []\n", "\n", "def random_response(message, history):\n", " return random.choice([\"Yes\", \"No\"])\n", "\n", "with gr.Blocks() as demo:\n", " radio = gr.Radio([\"Greeting\", \"Complaint\", \"Blank\"])\n", " chat = gr.ChatInterface(random_response, type=\"messages\")\n", " radio.change(prefill_chatbot, radio, chat.chatbot_value)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
def prefill_chatbot(choice):
|
| 5 |
+
if choice == "Greeting":
|
| 6 |
+
return [
|
| 7 |
+
{"role": "user", "content": "Hi there!"},
|
| 8 |
+
{"role": "assistant", "content": "Hello! How can I assist you today?"}
|
| 9 |
+
]
|
| 10 |
+
elif choice == "Complaint":
|
| 11 |
+
return [
|
| 12 |
+
{"role": "user", "content": "I'm not happy with the service."},
|
| 13 |
+
{"role": "assistant", "content": "I'm sorry to hear that. Can you please tell me more about the issue?"}
|
| 14 |
+
]
|
| 15 |
+
else:
|
| 16 |
+
return []
|
| 17 |
+
|
| 18 |
+
def random_response(message, history):
|
| 19 |
+
return random.choice(["Yes", "No"])
|
| 20 |
+
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
radio = gr.Radio(["Greeting", "Complaint", "Blank"])
|
| 23 |
+
chat = gr.ChatInterface(random_response, type="messages")
|
| 24 |
+
radio.change(prefill_chatbot, radio, chat.chatbot_value)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
demo.launch()
|