Spaces:
Sleeping
Sleeping
Lazar Radojevic
commited on
Commit
·
ec54cc0
1
Parent(s):
d765d3d
add streamlit
Browse files- Dockerfile +1 -0
- app.py +36 -0
- requirements.txt +1 -0
Dockerfile
CHANGED
@@ -31,3 +31,4 @@ EXPOSE 7860
|
|
31 |
|
32 |
# Command to run the FastAPI application
|
33 |
CMD ["python", "run.py"]
|
|
|
|
31 |
|
32 |
# Command to run the FastAPI application
|
33 |
CMD ["python", "run.py"]
|
34 |
+
CMD ["streamlit", "run", "app.py", "--server.port 7860"]
|
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
from typing import List, Tuple
|
4 |
+
|
5 |
+
API_URL = "http://localhost:7860/most_similar"
|
6 |
+
|
7 |
+
|
8 |
+
def get_similar_prompts(query: str, n: int) -> List[Tuple[float, str]]:
|
9 |
+
try:
|
10 |
+
response = requests.post(API_URL, json={"query": query, "n": n})
|
11 |
+
if response.status_code == 200:
|
12 |
+
return response.json().get("similar_prompts", [])
|
13 |
+
else:
|
14 |
+
st.error(f"Error: {response.status_code} - {response.text}")
|
15 |
+
return []
|
16 |
+
except requests.exceptions.RequestException as e:
|
17 |
+
st.error(f"Request error: {e}")
|
18 |
+
return []
|
19 |
+
|
20 |
+
|
21 |
+
st.title("Prompt Search Engine")
|
22 |
+
|
23 |
+
query = st.text_input("Enter a prompt:")
|
24 |
+
n = st.slider("Number of similar prompts to retrieve:", 1, 20, 5)
|
25 |
+
|
26 |
+
if st.button("Search"):
|
27 |
+
if query:
|
28 |
+
response = get_similar_prompts(query, n)
|
29 |
+
if response:
|
30 |
+
st.write(f"Top {n} similar prompts:")
|
31 |
+
for query_response in response:
|
32 |
+
st.write(
|
33 |
+
f"**Score:** {query_response['score']:.4f} | **Prompt:** {query_response['prompt']}"
|
34 |
+
)
|
35 |
+
else:
|
36 |
+
st.warning("Please enter a prompt to search.")
|
requirements.txt
CHANGED
@@ -5,3 +5,4 @@ sentence-transformers==3.0.1
|
|
5 |
numpy==1.26.4
|
6 |
fastapi==0.111.1
|
7 |
uvicorn==0.30.3
|
|
|
|
5 |
numpy==1.26.4
|
6 |
fastapi==0.111.1
|
7 |
uvicorn==0.30.3
|
8 |
+
streamlit==1.37.0
|