Spaces:
Sleeping
Sleeping
File size: 1,169 Bytes
7af929b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import streamlit as st
import requests
from typing import List, Tuple
import os
API_URL = os.getenv("API_URL")
def get_similar_prompts(query: str, n: int) -> List[Tuple[float, str]]:
try:
response = requests.post(f"{API_URL}/most_similar", json={"query": query, "n": n})
if response.status_code == 200:
return response.json().get("similar_prompts", [])
else:
st.error(f"Error: {response.status_code} - {response.text}")
return []
except requests.exceptions.RequestException as e:
st.error(f"Request error: {e}")
return []
st.title("Prompt Search Engine")
query = st.text_input("Enter a prompt:")
n = st.slider("Number of similar prompts to retrieve:", 1, 20, 5)
if st.button("Search"):
if query:
response = get_similar_prompts(query, n)
if response:
st.write(f"Top {n} similar prompts:")
for query_response in response:
st.write(
f"**Score:** {query_response['score']:.4f} | **Prompt:** {query_response['prompt']}"
)
else:
st.warning("Please enter a prompt to search.")
|