Spaces:
Sleeping
Sleeping
Updated APP
Browse files
app.py
CHANGED
|
@@ -19,7 +19,6 @@ class State(TypedDict):
|
|
| 19 |
category: str
|
| 20 |
sentiment: str
|
| 21 |
response: str
|
| 22 |
-
api_key: str
|
| 23 |
|
| 24 |
def init_llm(api_key: str):
|
| 25 |
os.environ["OPENAI_API_KEY"] = api_key
|
|
@@ -175,21 +174,24 @@ workflow.add_edge("escalate", END)
|
|
| 175 |
workflow.set_entry_point("categorize")
|
| 176 |
app = workflow.compile()
|
| 177 |
|
| 178 |
-
def run_customer_support(query: str, api_key: str) -> str:
|
| 179 |
-
""
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
# Build the Gradio UI.
|
| 195 |
with gr.Blocks(title="Customer Support Agent with Browser Use") as demo:
|
|
@@ -198,14 +200,28 @@ with gr.Blocks(title="Customer Support Agent with Browser Use") as demo:
|
|
| 198 |
|
| 199 |
with gr.Row():
|
| 200 |
with gr.Column():
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
submit_btn = gr.Button("Submit Query")
|
| 205 |
with gr.Column():
|
| 206 |
-
output_box = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
-
submit_btn.click(
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
| 210 |
if __name__ == "__main__":
|
| 211 |
demo.launch()
|
|
|
|
| 19 |
category: str
|
| 20 |
sentiment: str
|
| 21 |
response: str
|
|
|
|
| 22 |
|
| 23 |
def init_llm(api_key: str):
|
| 24 |
os.environ["OPENAI_API_KEY"] = api_key
|
|
|
|
| 174 |
workflow.set_entry_point("categorize")
|
| 175 |
app = workflow.compile()
|
| 176 |
|
| 177 |
+
async def run_customer_support(query: str, api_key: str = "") -> str:
|
| 178 |
+
if not api_key and not os.getenv("OPENAI_API_KEY"):
|
| 179 |
+
return "Error: Please provide an OpenAI API key"
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
if api_key:
|
| 183 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
| 184 |
+
|
| 185 |
+
llm = ChatOpenAI(temperature=0)
|
| 186 |
+
agent = Agent(
|
| 187 |
+
task=query,
|
| 188 |
+
llm=llm,
|
| 189 |
+
)
|
| 190 |
+
result = await agent.run()
|
| 191 |
+
return result
|
| 192 |
+
except Exception as e:
|
| 193 |
+
return f"Error: {str(e)}"
|
| 194 |
+
|
| 195 |
|
| 196 |
# Build the Gradio UI.
|
| 197 |
with gr.Blocks(title="Customer Support Agent with Browser Use") as demo:
|
|
|
|
| 200 |
|
| 201 |
with gr.Row():
|
| 202 |
with gr.Column():
|
| 203 |
+
api_key_input = gr.Textbox(
|
| 204 |
+
label="OpenAI API Key",
|
| 205 |
+
type="password",
|
| 206 |
+
placeholder="sk-..."
|
| 207 |
+
)
|
| 208 |
+
query_input = gr.Textbox(
|
| 209 |
+
label="Customer Query",
|
| 210 |
+
placeholder="Enter your query here...",
|
| 211 |
+
lines=3
|
| 212 |
+
)
|
| 213 |
submit_btn = gr.Button("Submit Query")
|
| 214 |
with gr.Column():
|
| 215 |
+
output_box = gr.Textbox(
|
| 216 |
+
label="Agent Response",
|
| 217 |
+
lines=10,
|
| 218 |
+
interactive=False
|
| 219 |
+
)
|
| 220 |
|
| 221 |
+
submit_btn.click(
|
| 222 |
+
fn=run_customer_support,
|
| 223 |
+
inputs=[query_input, api_key_input],
|
| 224 |
+
outputs=output_box
|
| 225 |
+
)
|
| 226 |
if __name__ == "__main__":
|
| 227 |
demo.launch()
|