freddyaboulton HF Staff commited on
Commit
2c72fa7
·
verified ·
1 Parent(s): a0c52f2

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 +1 -1
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: llm_openai"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio openai>=1.0.0"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# This is a simple general-purpose chatbot built on top of OpenAI API. \n", "# Before running this, make sure you have exported your OpenAI API key as an environment variable:\n", "# export OPENAI_API_KEY=\"your-openai-api-key\"\n", "\n", "from openai import OpenAI\n", "import gradio as gr\n", "\n", "client = OpenAI()\n", "\n", "def predict(message, history):\n", " history.append({\"role\": \"user\", \"content\": message})\n", " stream = client.chat.completions.create(messages=history, model=\"gpt-4o-mini\", stream=True)\n", " chunks = []\n", " for chunk in stream:\n", " chunks.append(chunk.choices[0].delta.content or \"\")\n", " yield \"\".join(chunks)\n", "\n", "demo = gr.ChatInterface(predict, type=\"messages\")\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: llm_openai"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio openai>=1.0.0"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# This is a simple general-purpose chatbot built on top of OpenAI API. \n", "# Before running this, make sure you have exported your OpenAI API key as an environment variable:\n", "# export OPENAI_API_KEY=\"your-openai-api-key\"\n", "\n", "from openai import OpenAI\n", "import gradio as gr\n", "\n", "client = OpenAI()\n", "\n", "def predict(message, history):\n", " history.append({\"role\": \"user\", \"content\": message})\n", " stream = client.chat.completions.create(messages=history, model=\"gpt-4o-mini\", stream=True)\n", " chunks = []\n", " for chunk in stream:\n", " chunks.append(chunk.choices[0].delta.content or \"\")\n", " yield \"\".join(chunks)\n", "\n", "demo = gr.ChatInterface(predict, api_name=\"chat\")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -15,7 +15,7 @@ def predict(message, history):
15
  chunks.append(chunk.choices[0].delta.content or "")
16
  yield "".join(chunks)
17
 
18
- demo = gr.ChatInterface(predict, type="messages")
19
 
20
  if __name__ == "__main__":
21
  demo.launch()
 
15
  chunks.append(chunk.choices[0].delta.content or "")
16
  yield "".join(chunks)
17
 
18
+ demo = gr.ChatInterface(predict, api_name="chat")
19
 
20
  if __name__ == "__main__":
21
  demo.launch()