aliabd HF staff commited on
Commit
849178c
1 Parent(s): e227cc9

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +7 -8
  2. requirements.txt +1 -2
  3. run.ipynb +1 -0
  4. run.py +34 -0
README.md CHANGED
@@ -1,13 +1,12 @@
 
1
  ---
2
- title: Agent Chatbot
3
- emoji: 🌖
4
  colorFrom: indigo
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.37.2
8
- app_file: app.py
9
  pinned: false
10
- license: apache-2.0
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: agent_chatbot
4
+ emoji: 🔥
5
  colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 4.38.0
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
requirements.txt CHANGED
@@ -1,2 +1 @@
1
- git+https://github.com/huggingface/transformers.git#egg=transformers[agents]
2
- https://gradio-builds.s3.amazonaws.com/542458a3d3185124a44c7400ebfb48012a508772/gradio-4.37.2-py3-none-any.whl
 
1
+ git+https://github.com/huggingface/transformers.git#egg=transformers[agents]
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: agent_chatbot"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio git+https://github.com/huggingface/transformers.git#egg=transformers[agents]"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/agent_chatbot/utils.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from gradio import ChatMessage\n", "from transformers import load_tool, ReactCodeAgent, HfEngine\n", "from utils import stream_from_transformers_agent\n", "\n", "# Import tool from Hub\n", "image_generation_tool = load_tool(\"m-ric/text-to-image\")\n", "\n", "\n", "llm_engine = HfEngine(\"meta-llama/Meta-Llama-3-70B-Instruct\")\n", "# Initialize the agent with both tools\n", "agent = ReactCodeAgent(tools=[image_generation_tool], llm_engine=llm_engine)\n", "\n", "\n", "def interact_with_agent(prompt, messages):\n", " messages.append(ChatMessage(role=\"user\", content=prompt))\n", " yield messages\n", " for msg in stream_from_transformers_agent(agent, prompt):\n", " messages.append(msg)\n", " yield messages\n", " yield messages\n", "\n", "\n", "with gr.Blocks() as demo:\n", " stored_message = gr.State([])\n", " chatbot = gr.Chatbot(label=\"Agent\",\n", " type=\"messages\",\n", " avatar_images=(None, \"https://em-content.zobj.net/source/twitter/53/robot-face_1f916.png\"))\n", " text_input = gr.Textbox(lines=1, label=\"Chat Message\")\n", " text_input.submit(lambda s: (s, \"\"), [text_input], [stored_message, text_input]).then(interact_with_agent, [stored_message, chatbot], [chatbot])\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio import ChatMessage
3
+ from transformers import load_tool, ReactCodeAgent, HfEngine
4
+ from utils import stream_from_transformers_agent
5
+
6
+ # Import tool from Hub
7
+ image_generation_tool = load_tool("m-ric/text-to-image")
8
+
9
+
10
+ llm_engine = HfEngine("meta-llama/Meta-Llama-3-70B-Instruct")
11
+ # Initialize the agent with both tools
12
+ agent = ReactCodeAgent(tools=[image_generation_tool], llm_engine=llm_engine)
13
+
14
+
15
+ def interact_with_agent(prompt, messages):
16
+ messages.append(ChatMessage(role="user", content=prompt))
17
+ yield messages
18
+ for msg in stream_from_transformers_agent(agent, prompt):
19
+ messages.append(msg)
20
+ yield messages
21
+ yield messages
22
+
23
+
24
+ with gr.Blocks() as demo:
25
+ stored_message = gr.State([])
26
+ chatbot = gr.Chatbot(label="Agent",
27
+ type="messages",
28
+ avatar_images=(None, "https://em-content.zobj.net/source/twitter/53/robot-face_1f916.png"))
29
+ text_input = gr.Textbox(lines=1, label="Chat Message")
30
+ text_input.submit(lambda s: (s, ""), [text_input], [stored_message, text_input]).then(interact_with_agent, [stored_message, chatbot], [chatbot])
31
+
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()