Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
|
|
4 |
|
5 |
# WARNING: It is not recommended to hardcode sensitive data like API tokens in code.
|
6 |
# Consider using environment variables or other secure methods for production applications.
|
@@ -28,7 +29,13 @@ def magic_function(input_text):
|
|
28 |
# Extract content from a standard chat completion response structure.
|
29 |
# This may need adjustment if the API has a different format.
|
30 |
content = response_json.get("choices", [{}])[0].get("message", {}).get("content", "Error: Could not parse response.")
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
except requests.exceptions.RequestException as e:
|
34 |
return f"API Request Error: {e}"
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
+
import re
|
5 |
|
6 |
# WARNING: It is not recommended to hardcode sensitive data like API tokens in code.
|
7 |
# Consider using environment variables or other secure methods for production applications.
|
|
|
29 |
# Extract content from a standard chat completion response structure.
|
30 |
# This may need adjustment if the API has a different format.
|
31 |
content = response_json.get("choices", [{}])[0].get("message", {}).get("content", "Error: Could not parse response.")
|
32 |
+
|
33 |
+
# Remove unwanted prefixes and characters from the response.
|
34 |
+
# This regex removes "Your Suggestion: " or "**Your Suggestion**: " from the beginning of the string, case-insensitively.
|
35 |
+
content = re.sub(r'^\s*(\*\*Your Suggestion\*\*:\s*|Your Suggestion:\s*)', '', content, flags=re.IGNORECASE)
|
36 |
+
content = content.replace("`", "")
|
37 |
+
|
38 |
+
return content.strip()
|
39 |
|
40 |
except requests.exceptions.RequestException as e:
|
41 |
return f"API Request Error: {e}"
|