alexpantex's picture
Upload app.py with huggingface_hub
cd2ebf8 verified
raw
history blame
1.19 kB
import streamlit as st
import requests
# Use localhost as FastAPI and Streamlit run in the same environment on Spaces
API_URL = "http://localhost:8000/search"
st.title("Prompt Search App")
st.write("Enter a query below to find similar prompts.")
query = st.text_input("Query:")
n_results = st.slider("Number of Results:", min_value=1, max_value=10, value=5)
if st.button("Search"):
if query.strip():
payload = {"query": query, "n_results": n_results}
try:
response = requests.post(API_URL, json=payload)
if response.status_code == 200:
data = response.json()
st.write(f"**Query:** {data['query']}")
st.write("**Similar Prompts:**")
for idx, result in enumerate(data["similar_queries"], 1):
st.write(f"{idx}. {result['prompt']} (Score: {result['score']:.4f})")
else:
st.error(f"API Error: {response.status_code} - {response.json().get('detail', 'No details available.')}")
except Exception as e:
st.error(f"Failed to connect to the API. Error: {e}")
else:
st.warning("Please enter a valid query.")