Spaces:
Sleeping
Sleeping
updated script
Browse files
app.py
CHANGED
|
@@ -182,14 +182,12 @@ async def run_customer_support(query: str, api_key: str = "") -> str:
|
|
| 182 |
"""
|
| 183 |
Main function called by Gradio upon submit.
|
| 184 |
- If user provided an API key, set it in the environment.
|
| 185 |
-
- Then run the workflow
|
| 186 |
- Return the final response from the workflow.
|
| 187 |
"""
|
| 188 |
-
# If no key is provided by user and none is in environment, show error.
|
| 189 |
if not api_key and not os.getenv("OPENAI_API_KEY"):
|
| 190 |
return "Error: Please provide an OpenAI API key."
|
| 191 |
-
|
| 192 |
-
# Set user-provided key in environment
|
| 193 |
if api_key:
|
| 194 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 195 |
|
|
@@ -201,12 +199,12 @@ async def run_customer_support(query: str, api_key: str = "") -> str:
|
|
| 201 |
"sentiment": "",
|
| 202 |
"response": ""
|
| 203 |
}
|
| 204 |
-
|
|
|
|
| 205 |
return final_state["response"]
|
| 206 |
except Exception as e:
|
| 207 |
return f"Error: {str(e)}"
|
| 208 |
|
| 209 |
-
|
| 210 |
# -------------------------------------------------------
|
| 211 |
# Build the Gradio UI
|
| 212 |
# -------------------------------------------------------
|
|
|
|
| 182 |
"""
|
| 183 |
Main function called by Gradio upon submit.
|
| 184 |
- If user provided an API key, set it in the environment.
|
| 185 |
+
- Then run the compiled workflow on the user's query.
|
| 186 |
- Return the final response from the workflow.
|
| 187 |
"""
|
|
|
|
| 188 |
if not api_key and not os.getenv("OPENAI_API_KEY"):
|
| 189 |
return "Error: Please provide an OpenAI API key."
|
| 190 |
+
|
|
|
|
| 191 |
if api_key:
|
| 192 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 193 |
|
|
|
|
| 199 |
"sentiment": "",
|
| 200 |
"response": ""
|
| 201 |
}
|
| 202 |
+
# Call `.run()` instead of `app(state)`
|
| 203 |
+
final_state = app.run(state)
|
| 204 |
return final_state["response"]
|
| 205 |
except Exception as e:
|
| 206 |
return f"Error: {str(e)}"
|
| 207 |
|
|
|
|
| 208 |
# -------------------------------------------------------
|
| 209 |
# Build the Gradio UI
|
| 210 |
# -------------------------------------------------------
|