Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import semantic_kernel
|
| 3 |
+
from plugins.sk_bing_plugin import BingPlugin
|
| 4 |
+
from plugins.sk_web_pages_plugin import WebPagesPlugin
|
| 5 |
+
from planning.autogen_planner import AutoGenPlanner
|
| 6 |
+
|
| 7 |
+
# Configure your credentials here
|
| 8 |
+
bing_api_key = "..." # Replace with your Bing API key
|
| 9 |
+
|
| 10 |
+
llm_config = {
|
| 11 |
+
"type": "openai", # "azure" or "openai"
|
| 12 |
+
"openai_api_key": "sk-...", # OpenAI API Key
|
| 13 |
+
"azure_deployment": "", # Azure OpenAI deployment name
|
| 14 |
+
"azure_api_key": "", # Azure OpenAI API key in the Azure portal
|
| 15 |
+
"azure_endpoint": "" # Endpoint URL for Azure OpenAI, e.g. https://contoso.openai.azure.com/
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
kernel = semantic_kernel.Kernel()
|
| 19 |
+
kernel.import_skill(BingPlugin(bing_api_key))
|
| 20 |
+
kernel.import_skill(WebPagesPlugin())
|
| 21 |
+
sk_planner = AutoGenPlanner(kernel, llm_config)
|
| 22 |
+
assistant = sk_planner.create_assistant_agent("Assistant")
|
| 23 |
+
|
| 24 |
+
def get_response(question, max_auto_reply):
|
| 25 |
+
worker = sk_planner.create_user_agent("Worker", max_auto_reply=max_auto_reply, human_input="NEVER")
|
| 26 |
+
worker.initiate_chat(assistant, message=question)
|
| 27 |
+
return worker.get_response()
|
| 28 |
+
|
| 29 |
+
iface = gr.Interface(fn=get_response, inputs=["text", "number"], outputs="text", inputs_label=["Question", "Max Auto Reply"])
|
| 30 |
+
iface.launch()
|