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.")