abhidgp1978 commited on
Commit
aa46ffb
·
verified ·
1 Parent(s): e865162

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -114,18 +114,25 @@ def summarize_with_cerebras(text):
114
  return "Summary not available."
115
 
116
  def log_search(name, email, country, query, results):
117
- """Download existing logs, append new log, and upload updated log file."""
118
-
119
  log_entry = {
120
  "timestamp": datetime.utcnow().isoformat(),
121
  "name": name,
122
  "email": email,
123
  "country": country,
124
  "query": query,
125
- "results_count": len(results)
 
 
 
 
 
 
 
 
126
  }
127
 
128
- # Step 1: Download existing log file if exists
129
  try:
130
  existing_log_path = hf_hub_download(
131
  repo_id=DATASET_REPO,
@@ -136,25 +143,21 @@ def log_search(name, email, country, query, results):
136
  with open(existing_log_path, "r", encoding="utf-8") as f:
137
  existing_lines = f.readlines()
138
  except Exception:
139
- # If file doesn't exist or download fails, start fresh
140
  existing_lines = []
141
 
142
- # Step 2: Append new entry
143
  existing_lines.append(json.dumps(log_entry) + "\n")
144
 
145
- # Step 3: Write combined logs to temp file
146
  tmp_file = tempfile.NamedTemporaryFile(delete=False, mode="w", encoding="utf-8")
147
  tmp_file.writelines(existing_lines)
148
  tmp_file.close()
149
 
150
- # Step 4: Upload updated file back to HF dataset repo
151
  upload_file(
152
  path_or_fileobj=tmp_file.name,
153
  path_in_repo=DATASET_FILE,
154
  repo_id=DATASET_REPO,
155
  token=HF_TOKEN,
156
  repo_type="dataset",
157
- commit_message="Appending new search log entry"
158
  )
159
 
160
  def search_and_summarize(name, email, country, query, session_id):
 
114
  return "Summary not available."
115
 
116
  def log_search(name, email, country, query, results):
117
+ """Log search to HF dataset including full results."""
 
118
  log_entry = {
119
  "timestamp": datetime.utcnow().isoformat(),
120
  "name": name,
121
  "email": email,
122
  "country": country,
123
  "query": query,
124
+ "results_count": len(results),
125
+ "results": [
126
+ {
127
+ "title": r.get("title"),
128
+ "source": r.get("source"),
129
+ "date": r.get("date"),
130
+ "link": r.get("link")
131
+ } for r in results
132
+ ]
133
  }
134
 
135
+ # Download existing logs
136
  try:
137
  existing_log_path = hf_hub_download(
138
  repo_id=DATASET_REPO,
 
143
  with open(existing_log_path, "r", encoding="utf-8") as f:
144
  existing_lines = f.readlines()
145
  except Exception:
 
146
  existing_lines = []
147
 
 
148
  existing_lines.append(json.dumps(log_entry) + "\n")
149
 
 
150
  tmp_file = tempfile.NamedTemporaryFile(delete=False, mode="w", encoding="utf-8")
151
  tmp_file.writelines(existing_lines)
152
  tmp_file.close()
153
 
 
154
  upload_file(
155
  path_or_fileobj=tmp_file.name,
156
  path_in_repo=DATASET_FILE,
157
  repo_id=DATASET_REPO,
158
  token=HF_TOKEN,
159
  repo_type="dataset",
160
+ commit_message="Appending new search log entry with results"
161
  )
162
 
163
  def search_and_summarize(name, email, country, query, session_id):