alexpantex commited on
Commit
cd2ebf8
·
verified ·
1 Parent(s): fb381b7

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # Use localhost as FastAPI and Streamlit run in the same environment on Spaces
5
+ API_URL = "http://localhost:8000/search"
6
+
7
+ st.title("Prompt Search App")
8
+ st.write("Enter a query below to find similar prompts.")
9
+
10
+ query = st.text_input("Query:")
11
+ n_results = st.slider("Number of Results:", min_value=1, max_value=10, value=5)
12
+
13
+ if st.button("Search"):
14
+ if query.strip():
15
+ payload = {"query": query, "n_results": n_results}
16
+ try:
17
+ response = requests.post(API_URL, json=payload)
18
+ if response.status_code == 200:
19
+ data = response.json()
20
+ st.write(f"**Query:** {data['query']}")
21
+ st.write("**Similar Prompts:**")
22
+ for idx, result in enumerate(data["similar_queries"], 1):
23
+ st.write(f"{idx}. {result['prompt']} (Score: {result['score']:.4f})")
24
+ else:
25
+ st.error(f"API Error: {response.status_code} - {response.json().get('detail', 'No details available.')}")
26
+ except Exception as e:
27
+ st.error(f"Failed to connect to the API. Error: {e}")
28
+ else:
29
+ st.warning("Please enter a valid query.")