Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import Flask, jsonify, request
import json
from scripts import search
from scripts.search import search_dif_languages
from scripts.search import search_dif_languages, change_top_descriptions
from scripts.rank import add_embeddings, get_score, get_top_results

# create main flask app (no templates)
Expand All @@ -13,9 +13,13 @@ def index():
return "hello, codefest"


@app.route("/search", methods=["GET", "POST"])
def search_page():
return "main page"
@app.route("/api/get-enhanced-descriptions", methods=["GET", "POST"])
def get_enhanced_descriptions():
input = request.get_json()
links = list(input['links'])
# gets enhanced descriptions as a list in the order the links were sent in
return jsonify(change_top_descriptions(links))


# takes the text prompt and returns json of top search reslts
@app.route("/api/get-search-result", methods=["GET", "POST"])
Expand Down
28 changes: 19 additions & 9 deletions backend/scripts/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,34 @@ def search_dif_languages(user_search: str, languages: list) -> dict:
get_score(search_data)

multilang_top_hits = get_top_results(search_data, 3)



return multilang_top_hits

def change_top_descriptions(top_hits: list):
"""
### Returns possible changed descriptions in top 3 hits
across all languages
- Returns new descriptions as list of strings from gpt api

#### args:
top_hits: list of strings (the links)
"""
# try to change the description of top 3 best results to revised summary
for hit in multilang_top_hits:
web_url = hit["link"]
enhanced = {}
for i, hit in enumerate(top_hits):
enhanced[hit] = ""
# try changing the snippet description for each entry in list
try:
page_description = get_website_description(web_url)
page_description = get_website_description(hit)

if page_description is not None:
hit["snippet"] = page_description
enhanced[hit] = page_description

# if it doesn't work just do nothing to snippet
except:
pass

return multilang_top_hits
enhanced[hit] = ""

return enhanced


# Debugging main functions code:
Expand Down