-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
florian
committed
Jun 15, 2024
1 parent
3ec5cc2
commit 7e6f683
Showing
22 changed files
with
357 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore everything in this directory | ||
* | ||
# Except this file | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react"; | ||
|
||
interface InfoBoxProps { | ||
infoBoxVisible: boolean; | ||
} | ||
|
||
const InfoBox: React.FC<InfoBoxProps> = ({ infoBoxVisible }) => { | ||
if (!infoBoxVisible) return null; | ||
|
||
return ( | ||
<div className="w-3/5 bg-white p-6 rounded-lg shadow-lg mt-4"> | ||
<h2 className="text-2xl font-bold mb-2">How does this work?</h2> | ||
<p className="text-gray-700"> | ||
This application allows you to search for Python packages on PyPi using | ||
natural language. An example query would be "a package that creates | ||
plots and beautiful visualizations". | ||
</p> | ||
<br /> | ||
<p className="text-gray-700"> | ||
Once you click search, your query will be matched against the summary | ||
and the first part of the description of all PyPi packages with more | ||
than 50 weekly downloads. The results are then scored based on their | ||
similarity and their number of weekly downloads, and the thirty best | ||
results are displayed in the table below. | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default InfoBox; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import axios from "axios"; | ||
|
||
interface Match { | ||
name: string; | ||
similarity: number; | ||
weekly_downloads: number; | ||
summary: string; | ||
} | ||
|
||
export const handleSearch = async ( | ||
query: string, | ||
sortField: string, | ||
sortDirection: string, | ||
setResults: React.Dispatch<React.SetStateAction<Match[]>>, | ||
setLoading: React.Dispatch<React.SetStateAction<boolean>>, | ||
setError: React.Dispatch<React.SetStateAction<string>>, | ||
) => { | ||
setLoading(true); | ||
setError(""); | ||
try { | ||
const response = await axios.post( | ||
"http://localhost:8000/search", | ||
{ | ||
query: query, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
); | ||
const fetchedResults: Match[] = response.data.matches; | ||
setResults(sortResults(fetchedResults, sortField, sortDirection)); | ||
} catch (error) { | ||
setError("Error fetching search results."); | ||
console.error("Error fetching search results:", error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
export const sortResults = ( | ||
data: Match[], | ||
field: string, | ||
direction: string, | ||
): Match[] => { | ||
return [...data].sort((a, b) => { | ||
if (a[field] < b[field]) return direction === "asc" ? -1 : 1; | ||
if (a[field] > b[field]) return direction === "asc" ? 1 : -1; | ||
return 0; | ||
}); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.