Lazar Radojevic commited on
Commit
45462fb
·
1 Parent(s): be043a6

finally working version :)

Browse files
Files changed (3) hide show
  1. frontend/app_ui.py +18 -4
  2. main.py +34 -0
  3. poe/common-tasks.toml +11 -2
frontend/app_ui.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import requests
3
 
4
  # Define the URL of the FastAPI service
5
- API_URL = "http://localhost:8000/most_similar" # Adjust if the FastAPI service is hosted elsewhere
6
 
7
 
8
  def get_similar_prompts(query, n):
@@ -15,13 +15,22 @@ def get_similar_prompts(query, n):
15
  return None
16
 
17
 
 
 
 
 
 
 
 
 
 
18
  def main():
19
  st.title("Prompt Similarity Finder")
20
 
21
  # User input for query
22
  query = st.text_input("Enter your query:", "")
23
  n = st.slider(
24
- "Number of similar prompts to retrieve:", min_value=1, max_value=20, value=5
25
  )
26
 
27
  if st.button("Find Similar Prompts"):
@@ -33,8 +42,13 @@ def main():
33
  if similar_prompts:
34
  st.subheader("Similar Prompts:")
35
  for item in similar_prompts:
36
- st.write(f"**Score:** {item['score']:.2f}")
37
- st.write(f"**Prompt:** {item['prompt']}")
 
 
 
 
 
38
  st.write("---")
39
  else:
40
  st.write("No similar prompts found.")
 
2
  import requests
3
 
4
  # Define the URL of the FastAPI service
5
+ API_URL = "https://lazarr19-prompt-engine.hf.space/most_similar" # Adjust if the FastAPI service is hosted elsewhere
6
 
7
 
8
  def get_similar_prompts(query, n):
 
15
  return None
16
 
17
 
18
+ def get_color(score):
19
+ if score >= 0.8:
20
+ return "green"
21
+ elif score >= 0.5:
22
+ return "orange"
23
+ else:
24
+ return "red"
25
+
26
+
27
  def main():
28
  st.title("Prompt Similarity Finder")
29
 
30
  # User input for query
31
  query = st.text_input("Enter your query:", "")
32
  n = st.slider(
33
+ "Number of similar prompts to retrieve:", min_value=1, max_value=40, value=5
34
  )
35
 
36
  if st.button("Find Similar Prompts"):
 
42
  if similar_prompts:
43
  st.subheader("Similar Prompts:")
44
  for item in similar_prompts:
45
+ score = item["score"]
46
+ color = get_color(score)
47
+ # Apply color only to the score part
48
+ st.markdown(
49
+ f"<p><strong>Score:</strong> <span style='color:{color};'>{score:.2f}</span> <br> <strong>Prompt:</strong> {item['prompt']}</p>",
50
+ unsafe_allow_html=True,
51
+ )
52
  st.write("---")
53
  else:
54
  st.write("No similar prompts found.")
main.py CHANGED
@@ -1,4 +1,5 @@
1
  from fastapi import FastAPI, HTTPException
 
2
  from pydantic import BaseModel
3
  from typing import List
4
  from src.search_engine import PromptSearchEngine
@@ -47,3 +48,36 @@ async def get_most_similar(query_request: QueryRequest):
47
  return response
48
  except Exception as e:
49
  raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI, HTTPException
2
+ from fastapi.responses import HTMLResponse
3
  from pydantic import BaseModel
4
  from typing import List
5
  from src.search_engine import PromptSearchEngine
 
48
  return response
49
  except Exception as e:
50
  raise HTTPException(status_code=500, detail=str(e))
51
+
52
+
53
+ @app.get("/", response_class=HTMLResponse)
54
+ async def home_page():
55
+ return HTMLResponse(
56
+ """
57
+ <!DOCTYPE html>
58
+ <html lang="en">
59
+ <head>
60
+ <meta charset="UTF-8">
61
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
62
+ <title>Prompt Search Engine</title>
63
+ <style>
64
+ body { font-family: Arial, sans-serif; margin: 20px; }
65
+ h1 { color: #333; }
66
+ p { margin-bottom: 10px; }
67
+ code { background: #f4f4f4; padding: 2px 4px; border-radius: 4px; }
68
+ .container { max-width: 800px; margin: 0 auto; }
69
+ </style>
70
+ </head>
71
+ <body>
72
+ <div class="container">
73
+ <h1>Prompt Search Engine API</h1>
74
+ <p>Use this API to find similar prompts based on a query.</p>
75
+ <h2>POST /most_similar</h2>
76
+ <p><strong>Request:</strong> <code>{"query": "string", "n": 5}</code></p>
77
+ <p><strong>Response:</strong> <code>{"similar_prompts": [{"score": 0.95, "prompt": "Example prompt 1"}]}</code></p>
78
+ <p>For more info, visit <a href="https://github.com/your-repository">GitHub</a>.</p>
79
+ </div>
80
+ </body>
81
+ </html>
82
+ """
83
+ )
poe/common-tasks.toml CHANGED
@@ -52,5 +52,14 @@ help = "Run all checks on the code base"
52
  sequence = ["style", "types", "lint", "clean"]
53
 
54
  [tool.poe.tasks.ui]
55
- help = "Start the UI"
56
- cmd = "streamlit run ./frontend/app_ui.py"
 
 
 
 
 
 
 
 
 
 
52
  sequence = ["style", "types", "lint", "clean"]
53
 
54
  [tool.poe.tasks.ui]
55
+ help = "Start the UI"
56
+ cmd = "streamlit run ./frontend/app_ui.py"
57
+
58
+ [tool.poe.tasks.build]
59
+ help = "Build the Docker image"
60
+ cmd = "docker build -t prompt-search-engine ."
61
+
62
+ [tool.poe.tasks.start]
63
+ help = "Run the Docker container"
64
+ cmd = "docker run -d -p 8000:8000 prompt-serach-engine"
65
+