Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,20 +19,19 @@ GOOGLE_CX = os.getenv("GOOGLE_CX")
|
|
| 19 |
# -----------------------------
|
| 20 |
# Helper Functions
|
| 21 |
# -----------------------------
|
| 22 |
-
def google_search(query, site_filter=None, num=3, region=
|
| 23 |
if not GOOGLE_API_KEY or not GOOGLE_CX:
|
| 24 |
-
return ["⚠️ Missing Google API credentials in Hugging Face Secrets"]
|
| 25 |
|
| 26 |
url = "https://www.googleapis.com/customsearch/v1"
|
| 27 |
params = {
|
| 28 |
"q": query,
|
| 29 |
"key": GOOGLE_API_KEY,
|
| 30 |
"cx": GOOGLE_CX,
|
| 31 |
-
"num": num
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
-
if region and region != "Global":
|
| 34 |
-
params["gl"] = region.lower()
|
| 35 |
-
params["cr"] = f"country{region.upper()}"
|
| 36 |
|
| 37 |
resp = requests.get(url, params=params)
|
| 38 |
data = resp.json()
|
|
@@ -54,7 +53,7 @@ def google_search(query, site_filter=None, num=3, region=None):
|
|
| 54 |
|
| 55 |
def generate_channel_reason(product_desc, channel_name):
|
| 56 |
prompt = f"Product description: {product_desc}\nChannel: {channel_name}\nExplain why this channel is suitable for this product in 1-2 sentences."
|
| 57 |
-
reason = generator(prompt, max_new_tokens=60, do_sample=True)[0]['generated_text']
|
| 58 |
return reason.replace(prompt, '').strip()
|
| 59 |
|
| 60 |
|
|
@@ -94,7 +93,7 @@ with gr.Blocks() as demo:
|
|
| 94 |
region_dropdown = gr.Dropdown(
|
| 95 |
label="Select Region (optional)",
|
| 96 |
choices=["Global", "IN", "US", "UK", "CA", "AU"],
|
| 97 |
-
value="
|
| 98 |
)
|
| 99 |
out = gr.Markdown(label="Suggested Channels")
|
| 100 |
|
|
|
|
| 19 |
# -----------------------------
|
| 20 |
# Helper Functions
|
| 21 |
# -----------------------------
|
| 22 |
+
def google_search(query, site_filter=None, num=3, region="IN"):
|
| 23 |
if not GOOGLE_API_KEY or not GOOGLE_CX:
|
| 24 |
+
return [("⚠️ Missing Google API credentials in Hugging Face Secrets", "")]
|
| 25 |
|
| 26 |
url = "https://www.googleapis.com/customsearch/v1"
|
| 27 |
params = {
|
| 28 |
"q": query,
|
| 29 |
"key": GOOGLE_API_KEY,
|
| 30 |
"cx": GOOGLE_CX,
|
| 31 |
+
"num": num,
|
| 32 |
+
"gl": region.lower(), # region set to India
|
| 33 |
+
"cr": f"country{region.upper()}"
|
| 34 |
}
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
resp = requests.get(url, params=params)
|
| 37 |
data = resp.json()
|
|
|
|
| 53 |
|
| 54 |
def generate_channel_reason(product_desc, channel_name):
|
| 55 |
prompt = f"Product description: {product_desc}\nChannel: {channel_name}\nExplain why this channel is suitable for this product in 1-2 sentences."
|
| 56 |
+
reason = generator(prompt, max_new_tokens=60, do_sample=True, temperature=0.7)[0]['generated_text']
|
| 57 |
return reason.replace(prompt, '').strip()
|
| 58 |
|
| 59 |
|
|
|
|
| 93 |
region_dropdown = gr.Dropdown(
|
| 94 |
label="Select Region (optional)",
|
| 95 |
choices=["Global", "IN", "US", "UK", "CA", "AU"],
|
| 96 |
+
value="IN" # Default set to India
|
| 97 |
)
|
| 98 |
out = gr.Markdown(label="Suggested Channels")
|
| 99 |
|