switch to huggingface API
Browse filesIn this pr we switch crewai from openai to huggingface apis, example at work (as demonstrated at https://huggingface.co/spaces/not-lain/CrewAI-Gradio-Support-Agent )
![image.png](https://cdn-uploads.huggingface.co/production/uploads/6527e89a8808d80ccff88b7a/EFuJjG0enXyOihbhY_WxN.png)
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
# imports
|
2 |
import gradio as gr
|
3 |
-
from crewai import Agent, Task, Crew
|
4 |
from crewai_tools import ScrapeWebsiteTool
|
5 |
import os
|
6 |
import queue
|
@@ -39,7 +39,10 @@ class SupportCrew:
|
|
39 |
if not self.api_key:
|
40 |
raise ValueError("OpenAI API key is required")
|
41 |
|
42 |
-
|
|
|
|
|
|
|
43 |
self.scrape_tool = ScrapeWebsiteTool(website_url=website_url)
|
44 |
|
45 |
self.support_agent = Agent(
|
@@ -50,6 +53,7 @@ class SupportCrew:
|
|
50 |
"You need to make sure that you provide the best support! "
|
51 |
"Make sure to provide full complete answers, and make no assumptions."
|
52 |
),
|
|
|
53 |
allow_delegation=False,
|
54 |
verbose=True
|
55 |
)
|
@@ -63,6 +67,7 @@ class SupportCrew:
|
|
63 |
"You need to make sure that the support representative is providing full "
|
64 |
"complete answers, and make no assumptions."
|
65 |
),
|
|
|
66 |
verbose=True
|
67 |
)
|
68 |
|
@@ -222,10 +227,10 @@ def create_demo():
|
|
222 |
with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
223 |
gr.Markdown("# 🎯 AI Customer Support Crew")
|
224 |
gr.Markdown("This is a friendly, high-performing multi-agent application built with Gradio and CrewAI. Enter a webpage URL and your questions from that webpage.")
|
225 |
-
|
226 |
-
label='
|
227 |
type='password',
|
228 |
-
placeholder='Type your
|
229 |
interactive=True
|
230 |
)
|
231 |
|
@@ -290,16 +295,16 @@ def create_demo():
|
|
290 |
|
291 |
def show_interface():
|
292 |
return {
|
293 |
-
|
294 |
chatbot: gr.Chatbot(visible=True),
|
295 |
inquiry: gr.Textbox(visible=True),
|
296 |
website_url: gr.Textbox(visible=True),
|
297 |
btn: gr.Button(visible=True)
|
298 |
}
|
299 |
|
300 |
-
|
301 |
-
btn.click(process_input, [inquiry, website_url, chatbot,
|
302 |
-
inquiry.submit(process_input, [inquiry, website_url, chatbot,
|
303 |
|
304 |
return demo
|
305 |
|
|
|
1 |
# imports
|
2 |
import gradio as gr
|
3 |
+
from crewai import Agent, Task, Crew, LLM
|
4 |
from crewai_tools import ScrapeWebsiteTool
|
5 |
import os
|
6 |
import queue
|
|
|
39 |
if not self.api_key:
|
40 |
raise ValueError("OpenAI API key is required")
|
41 |
|
42 |
+
self.llm = LLM(
|
43 |
+
model="huggingface/meta-llama/Llama-3.3-70B-Instruct",
|
44 |
+
api_key=self.api_key,
|
45 |
+
)
|
46 |
self.scrape_tool = ScrapeWebsiteTool(website_url=website_url)
|
47 |
|
48 |
self.support_agent = Agent(
|
|
|
53 |
"You need to make sure that you provide the best support! "
|
54 |
"Make sure to provide full complete answers, and make no assumptions."
|
55 |
),
|
56 |
+
llm = self.llm,
|
57 |
allow_delegation=False,
|
58 |
verbose=True
|
59 |
)
|
|
|
67 |
"You need to make sure that the support representative is providing full "
|
68 |
"complete answers, and make no assumptions."
|
69 |
),
|
70 |
+
llm = self.llm,
|
71 |
verbose=True
|
72 |
)
|
73 |
|
|
|
227 |
with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
228 |
gr.Markdown("# 🎯 AI Customer Support Crew")
|
229 |
gr.Markdown("This is a friendly, high-performing multi-agent application built with Gradio and CrewAI. Enter a webpage URL and your questions from that webpage.")
|
230 |
+
HF_api_key = gr.Textbox(
|
231 |
+
label='HuggingFace API Key',
|
232 |
type='password',
|
233 |
+
placeholder='Type your HuggingFace API Key and press Enter to access the app...',
|
234 |
interactive=True
|
235 |
)
|
236 |
|
|
|
295 |
|
296 |
def show_interface():
|
297 |
return {
|
298 |
+
HF_api_key: gr.Textbox(visible=False),
|
299 |
chatbot: gr.Chatbot(visible=True),
|
300 |
inquiry: gr.Textbox(visible=True),
|
301 |
website_url: gr.Textbox(visible=True),
|
302 |
btn: gr.Button(visible=True)
|
303 |
}
|
304 |
|
305 |
+
HF_api_key.submit(show_interface, None, [HF_api_key, chatbot, inquiry, website_url, btn])
|
306 |
+
btn.click(process_input, [inquiry, website_url, chatbot, HF_api_key], [chatbot])
|
307 |
+
inquiry.submit(process_input, [inquiry, website_url, chatbot, HF_api_key], [chatbot])
|
308 |
|
309 |
return demo
|
310 |
|