Spaces:
Sleeping
Sleeping
initial commit
Browse files- app.py +53 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
st.title("Prompt Search Engine")
|
5 |
+
st.write("Enter a prompt to find the top *n* similar prompts.")
|
6 |
+
|
7 |
+
# User input prompt
|
8 |
+
prompt = st.text_input("Enter your prompt here:")
|
9 |
+
|
10 |
+
# Input for n
|
11 |
+
n = st.number_input("Number of similar prompts (n):", min_value=1, max_value=30, value=5, step=1)
|
12 |
+
|
13 |
+
if st.button("Search"):
|
14 |
+
# Make sure the prompt is not empty
|
15 |
+
if prompt.strip() == "":
|
16 |
+
st.warning("Please enter a prompt.")
|
17 |
+
else:
|
18 |
+
# API endpoint
|
19 |
+
api_url = "https://anja97-prompt-search-engine.hf.space/search"
|
20 |
+
|
21 |
+
# Prepare the payload
|
22 |
+
payload = {
|
23 |
+
"query": prompt,
|
24 |
+
"n": int(n)
|
25 |
+
}
|
26 |
+
|
27 |
+
# Send the POST request
|
28 |
+
try:
|
29 |
+
with st.spinner('Searching for similar prompts...'):
|
30 |
+
response = requests.post(api_url, json=payload, timeout=30)
|
31 |
+
# Check if the request was successful
|
32 |
+
if response.status_code == 200:
|
33 |
+
data = response.json()
|
34 |
+
results = data.get("results", [])
|
35 |
+
if results:
|
36 |
+
# Display the results
|
37 |
+
st.success(f"Top {n} similar prompts:")
|
38 |
+
for i, item in enumerate(results, start=1):
|
39 |
+
score = item.get("score", 0)
|
40 |
+
similar_prompt = item.get("prompt", "")
|
41 |
+
st.markdown(f"### Result {i}")
|
42 |
+
st.write(f"**Similarity score:** {score:.4f}")
|
43 |
+
st.write(f"**Prompt:** {similar_prompt}")
|
44 |
+
st.write("---")
|
45 |
+
else:
|
46 |
+
st.info("No similar prompts found.")
|
47 |
+
else:
|
48 |
+
st.error(f"API Error: {response.status_code} - {response.text}")
|
49 |
+
except requests.exceptions.Timeout:
|
50 |
+
st.error("The request timed out. Please try again later.")
|
51 |
+
except Exception as e:
|
52 |
+
st.error(f"An error occurred: {e}")
|
53 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sentence-transformers
|
2 |
+
numpy
|
3 |
+
datasets
|
4 |
+
fastapi
|
5 |
+
uvicorn
|
6 |
+
streamlit
|