kaiku03 commited on
Commit
eecc961
·
verified ·
1 Parent(s): ebc9c52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -14
app.py CHANGED
@@ -35,26 +35,93 @@ def embed_query(text: str):
35
 
36
  def search_games(query):
37
  if not query.strip():
38
- return "Please enter a query."
39
  q_emb = embed_query(query)
40
  scores, retrieved_ds = ds.get_nearest_examples("embeddings", q_emb, k=5)
41
- results = []
42
  for name, desc, dist in zip(
43
  retrieved_ds["game_name"],
44
  retrieved_ds["game_description"],
45
  scores
46
  ):
47
- results.append(f"**{name}**\n\n{desc}\n\nDistance: {dist:.4f}")
48
- return "\n\n---\n\n".join(results)
49
-
50
- # Build Gradio interface
51
- iface = gr.Interface(
52
- fn=search_games,
53
- inputs=gr.Textbox(lines=2, placeholder="Enter your game query here..."),
54
- outputs=gr.Markdown(),
55
- title="Steam Games Semantic Search",
56
- description="Search similar Steam games by semantic similarity."
57
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  if __name__ == "__main__":
60
- iface.launch()
 
35
 
36
  def search_games(query):
37
  if not query.strip():
38
+ return ""
39
  q_emb = embed_query(query)
40
  scores, retrieved_ds = ds.get_nearest_examples("embeddings", q_emb, k=5)
41
+ results_html = ""
42
  for name, desc, dist in zip(
43
  retrieved_ds["game_name"],
44
  retrieved_ds["game_description"],
45
  scores
46
  ):
47
+ results_html += f"""
48
+ <div class="result">
49
+ <div class="title">{name}</div>
50
+ <div class="description">{desc}</div>
51
+ <div class="distance">Distance: {dist:.4f}</div>
52
+ </div>
53
+ """
54
+ return results_html
55
+
56
+ custom_css = """
57
+ <style>
58
+ body, .gradio-container {
59
+ font-family: Arial, sans-serif;
60
+ margin: 2em;
61
+ background: url('/static/img/tlou.jpg') no-repeat center center fixed;
62
+ background-size: cover;
63
+ color: #fff;
64
+ text-shadow: 0 1px 2px rgba(0,0,0,0.8);
65
+ }
66
+ input, textarea, button {
67
+ font-size: 1em;
68
+ padding: 0.7em;
69
+ border: 1px solid #444;
70
+ border-radius: 0.4em;
71
+ background: rgba(0,0,0,0.6);
72
+ color: #fff;
73
+ box-sizing: border-box;
74
+ transition: box-shadow 0.2s;
75
+ }
76
+ input:focus, textarea:focus {
77
+ outline: none;
78
+ box-shadow: 0 0 6px 2px #88aaff;
79
+ background: rgba(10, 30, 80, 0.7);
80
+ }
81
+ button {
82
+ cursor: pointer;
83
+ border: 1px solid #444;
84
+ background: rgba(0,0,0,0.7);
85
+ color: #fff;
86
+ transition: background 0.2s;
87
+ font-size: 1.1em;
88
+ }
89
+ button:hover {
90
+ background: rgba(50,70,140,0.85);
91
+ }
92
+ .result {
93
+ border-bottom: 1px solid rgba(255,255,255,0.3);
94
+ padding: 1em 0;
95
+ }
96
+ .title {
97
+ font-weight: bold;
98
+ font-size: 1.2em;
99
+ }
100
+ .description { margin-top: 0.5em; }
101
+ .distance {
102
+ color: rgba(255,255,255,0.7);
103
+ font-size: 0.9em;
104
+ margin-top: 0.3em;
105
+ }
106
+ </style>
107
+ """
108
+
109
+ with gr.Blocks() as demo:
110
+ gr.HTML("<h2>Steam Game Semantic Search AI Demo (Trained on 200 games)</h2>")
111
+ gr.HTML("<h5>by: Alexis Mandario</h5>")
112
+ gr.HTML("""
113
+ <h5>Note: This web app fetches, tokenizes, and embeds 200 games from "Steam" (a gaming platform) using its API.
114
+ Only the games included in the training data will appear in the search results.
115
+ Only the top 5 similar games will be shown.</h5>
116
+ """)
117
+
118
+ query = gr.Textbox(placeholder="Enter search query: Describe the game you want here.", lines=1)
119
+ submit_btn = gr.Button("Search")
120
+ results = gr.HTML()
121
+
122
+ submit_btn.click(search_games, inputs=query, outputs=results)
123
+
124
+ gr.HTML(custom_css)
125
 
126
  if __name__ == "__main__":
127
+ demo.launch()