Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +8 -4
- templates/index.html +1 -1
app.py
CHANGED
@@ -89,6 +89,9 @@ def index():
|
|
89 |
query = request.args.get('query')
|
90 |
if not repo_name:
|
91 |
return render_template('no_repo.html')
|
|
|
|
|
|
|
92 |
return render_template('index.html', repo_name=repo_name, query=query)
|
93 |
|
94 |
@app.route('/search', methods=['POST'])
|
@@ -99,9 +102,6 @@ def search():
|
|
99 |
if not repo_name:
|
100 |
return jsonify({'error': 'No repository provided'}), 400
|
101 |
|
102 |
-
if not repo_name.startswith('spaces/') and not repo_name.startswith('datasets/'):
|
103 |
-
repo_name = f'models/{repo_name}'
|
104 |
-
repo_name = '/'.join(repo_name.split('/')[:3])
|
105 |
if not query:
|
106 |
return jsonify({'error': 'No query provided'}), 400
|
107 |
|
@@ -115,10 +115,14 @@ def search():
|
|
115 |
query_parser = QueryParser("content", ix.schema)
|
116 |
q = query_parser.parse(query)
|
117 |
results = searcher.search(q)
|
118 |
-
|
|
|
|
|
|
|
119 |
# Format results
|
120 |
formatted_results = [{
|
121 |
'discussion_id': escape(result['discussion_id']),
|
|
|
122 |
'title': escape(result['title']),
|
123 |
'author': escape(result['author']),
|
124 |
'excerpt': bleach.clean(result.highlights("content"), tags=['b'], strip=True),
|
|
|
89 |
query = request.args.get('query')
|
90 |
if not repo_name:
|
91 |
return render_template('no_repo.html')
|
92 |
+
if not repo_name.startswith('spaces/') and not repo_name.startswith('datasets/') and not repo_name.startswith('models/'):
|
93 |
+
repo_name = f'models/{repo_name}'
|
94 |
+
repo_name = '/'.join(repo_name.split('/')[:3])
|
95 |
return render_template('index.html', repo_name=repo_name, query=query)
|
96 |
|
97 |
@app.route('/search', methods=['POST'])
|
|
|
102 |
if not repo_name:
|
103 |
return jsonify({'error': 'No repository provided'}), 400
|
104 |
|
|
|
|
|
|
|
105 |
if not query:
|
106 |
return jsonify({'error': 'No query provided'}), 400
|
107 |
|
|
|
115 |
query_parser = QueryParser("content", ix.schema)
|
116 |
q = query_parser.parse(query)
|
117 |
results = searcher.search(q)
|
118 |
+
if repo_name.startswith('models/'):
|
119 |
+
url_repo_name = repo_name[7:]
|
120 |
+
else:
|
121 |
+
url_repo_name = repo_name
|
122 |
# Format results
|
123 |
formatted_results = [{
|
124 |
'discussion_id': escape(result['discussion_id']),
|
125 |
+
'url': f'https://huggingface.co/{url_repo_name}/discussions/{result["discussion_id"]}',
|
126 |
'title': escape(result['title']),
|
127 |
'author': escape(result['author']),
|
128 |
'excerpt': bleach.clean(result.highlights("content"), tags=['b'], strip=True),
|
templates/index.html
CHANGED
@@ -301,7 +301,7 @@
|
|
301 |
|
302 |
return filteredResults
|
303 |
.map(result => `
|
304 |
-
<a href="
|
305 |
class="result-card${!result.is_open ? ' closed' : ''}"
|
306 |
target="_blank" style="text-decoration: none;">
|
307 |
<div class="type-icon-container">
|
|
|
301 |
|
302 |
return filteredResults
|
303 |
.map(result => `
|
304 |
+
<a href="${result.url}"
|
305 |
class="result-card${!result.is_open ? ' closed' : ''}"
|
306 |
target="_blank" style="text-decoration: none;">
|
307 |
<div class="type-icon-container">
|