Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,6 +28,7 @@ SYSTEM_PROMPT = (
|
|
| 28 |
"You are Talk GTE β a friendly AI assistant created by Vibow AI. "
|
| 29 |
"GTE means Generative Text Expert in Vibow AI. "
|
| 30 |
"Vibow AI created in 29 June 2025 and Talk GTE created in 23 October 2025. "
|
|
|
|
| 31 |
"Talk GTE have approximately 1 trillion parameters. "
|
| 32 |
"Stay positive, kind, and expert. "
|
| 33 |
"Always capitalize the first letter of sentences. "
|
|
@@ -79,18 +80,16 @@ def text_to_speech(text: str) -> bytes:
|
|
| 79 |
return b""
|
| 80 |
|
| 81 |
# =========================
|
| 82 |
-
# π SerpAPI with
|
| 83 |
# =========================
|
| 84 |
def serpapi_search(query: str, location=None, num_results=3):
|
| 85 |
print(f"\n[SEARCH] π Starting search for: '{query}'")
|
| 86 |
|
| 87 |
-
# Detect Indonesian keywords to determine if search should be ID-focused
|
| 88 |
indonesian_keywords = ["di jakarta", "di bali", "di bekasi", "di surabaya", "di bandung",
|
| 89 |
"di indonesia", "di yogyakarta", "di medan", "di semarang",
|
| 90 |
"termurah", "terbaik di", "dekat", "murah"]
|
| 91 |
is_indonesian_query = any(kw in query.lower() for kw in indonesian_keywords)
|
| 92 |
|
| 93 |
-
# Set location and language based on query
|
| 94 |
if is_indonesian_query:
|
| 95 |
country = "id"
|
| 96 |
lang = "id"
|
|
@@ -113,9 +112,21 @@ def serpapi_search(query: str, location=None, num_results=3):
|
|
| 113 |
|
| 114 |
results = []
|
| 115 |
images = []
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
try:
|
| 118 |
-
#
|
| 119 |
r = requests.get(url, params=params, timeout=10)
|
| 120 |
r.raise_for_status()
|
| 121 |
data = r.json()
|
|
@@ -128,7 +139,7 @@ def serpapi_search(query: str, location=None, num_results=3):
|
|
| 128 |
"link": item.get("link", "")
|
| 129 |
})
|
| 130 |
|
| 131 |
-
#
|
| 132 |
img_params = {
|
| 133 |
"q": query,
|
| 134 |
"engine": "google_images",
|
|
@@ -140,15 +151,21 @@ def serpapi_search(query: str, location=None, num_results=3):
|
|
| 140 |
img_r = requests.get(url, params=img_params, timeout=10)
|
| 141 |
img_r.raise_for_status()
|
| 142 |
img_data = img_r.json()
|
|
|
|
| 143 |
if "images_results" in img_data:
|
| 144 |
for img in img_data["images_results"][:3]:
|
| 145 |
img_url = img.get("original", img.get("thumbnail", ""))
|
| 146 |
if img_url:
|
| 147 |
-
|
|
|
|
|
|
|
| 148 |
|
| 149 |
# Debug JSON
|
| 150 |
-
print("[DEBUG] πΉ SerpAPI JSON output:")
|
| 151 |
-
print(json.dumps({
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
return {"results": results, "images": images}
|
| 154 |
|
|
|
|
| 28 |
"You are Talk GTE β a friendly AI assistant created by Vibow AI. "
|
| 29 |
"GTE means Generative Text Expert in Vibow AI. "
|
| 30 |
"Vibow AI created in 29 June 2025 and Talk GTE created in 23 October 2025. "
|
| 31 |
+
"The owner of Vibow AI is Nick Mclen. "
|
| 32 |
"Talk GTE have approximately 1 trillion parameters. "
|
| 33 |
"Stay positive, kind, and expert. "
|
| 34 |
"Always capitalize the first letter of sentences. "
|
|
|
|
| 80 |
return b""
|
| 81 |
|
| 82 |
# =========================
|
| 83 |
+
# π SerpAPI with Base64 Image Conversion
|
| 84 |
# =========================
|
| 85 |
def serpapi_search(query: str, location=None, num_results=3):
|
| 86 |
print(f"\n[SEARCH] π Starting search for: '{query}'")
|
| 87 |
|
|
|
|
| 88 |
indonesian_keywords = ["di jakarta", "di bali", "di bekasi", "di surabaya", "di bandung",
|
| 89 |
"di indonesia", "di yogyakarta", "di medan", "di semarang",
|
| 90 |
"termurah", "terbaik di", "dekat", "murah"]
|
| 91 |
is_indonesian_query = any(kw in query.lower() for kw in indonesian_keywords)
|
| 92 |
|
|
|
|
| 93 |
if is_indonesian_query:
|
| 94 |
country = "id"
|
| 95 |
lang = "id"
|
|
|
|
| 112 |
|
| 113 |
results = []
|
| 114 |
images = []
|
| 115 |
+
|
| 116 |
+
# π§© Helper: convert image URL to base64 safely
|
| 117 |
+
def url_to_base64(img_url):
|
| 118 |
+
try:
|
| 119 |
+
r = requests.get(img_url, timeout=6)
|
| 120 |
+
if r.status_code == 200 and r.content:
|
| 121 |
+
mime = r.headers.get("Content-Type", "image/jpeg")
|
| 122 |
+
encoded = base64.b64encode(r.content).decode()
|
| 123 |
+
return f"data:{mime};base64,{encoded}"
|
| 124 |
+
except Exception as e:
|
| 125 |
+
print(f"[IMG] β οΈ Failed to convert {img_url}: {e}")
|
| 126 |
+
return None
|
| 127 |
+
|
| 128 |
try:
|
| 129 |
+
# --- TEXT SEARCH ---
|
| 130 |
r = requests.get(url, params=params, timeout=10)
|
| 131 |
r.raise_for_status()
|
| 132 |
data = r.json()
|
|
|
|
| 139 |
"link": item.get("link", "")
|
| 140 |
})
|
| 141 |
|
| 142 |
+
# --- IMAGE SEARCH ---
|
| 143 |
img_params = {
|
| 144 |
"q": query,
|
| 145 |
"engine": "google_images",
|
|
|
|
| 151 |
img_r = requests.get(url, params=img_params, timeout=10)
|
| 152 |
img_r.raise_for_status()
|
| 153 |
img_data = img_r.json()
|
| 154 |
+
|
| 155 |
if "images_results" in img_data:
|
| 156 |
for img in img_data["images_results"][:3]:
|
| 157 |
img_url = img.get("original", img.get("thumbnail", ""))
|
| 158 |
if img_url:
|
| 159 |
+
img_base64 = url_to_base64(img_url)
|
| 160 |
+
if img_base64:
|
| 161 |
+
images.append(img_base64)
|
| 162 |
|
| 163 |
# Debug JSON
|
| 164 |
+
print("[DEBUG] πΉ SerpAPI JSON output (base64 images trimmed):")
|
| 165 |
+
print(json.dumps({
|
| 166 |
+
"results": results,
|
| 167 |
+
"images": [i[:100] + "..." for i in images]
|
| 168 |
+
}, indent=2))
|
| 169 |
|
| 170 |
return {"results": results, "images": images}
|
| 171 |
|