Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,8 +23,6 @@ desc_col = get_col_name(['description', 'longDescription', 'shortDescription',
|
|
| 23 |
lang_col = get_col_name(['languageCodesISO2A', 'primaryLanguage', 'languages', 'language'], df.columns)
|
| 24 |
rating_col = 'averageUserRating'
|
| 25 |
|
| 26 |
-
print(f"π Mapped Columns: Image='{image_col}', Desc='{desc_col}', Rating='{rating_col}', Lang='{lang_col}'")
|
| 27 |
-
|
| 28 |
print("β³ Loading AI Model...")
|
| 29 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 30 |
print("β
Ready!")
|
|
@@ -45,15 +43,11 @@ def search_apps(user_query):
|
|
| 45 |
top_results = df_results.sort_values(by="similarity_score", ascending=False).head(3)
|
| 46 |
|
| 47 |
# --- HTML GENERATION ---
|
| 48 |
-
|
| 49 |
-
# 1. The Header Message
|
| 50 |
html_content = """
|
| 51 |
<div style="margin-bottom: 20px; text-align: center;">
|
| 52 |
<h3 style="color: #374151; margin: 0;">Here is what our recommendation system found for you:</h3>
|
| 53 |
</div>
|
| 54 |
"""
|
| 55 |
-
|
| 56 |
-
# 2. The Cards Container
|
| 57 |
html_content += '<div style="display: flex; gap: 20px; justify-content: center; flex-wrap: wrap;">'
|
| 58 |
|
| 59 |
for _, row in top_results.iterrows():
|
|
@@ -66,10 +60,7 @@ def search_apps(user_query):
|
|
| 66 |
|
| 67 |
# Rating Logic
|
| 68 |
score = row.get(rating_col, 0)
|
| 69 |
-
if pd.isna(score) or score == 0
|
| 70 |
-
rating_text = "No ratings yet"
|
| 71 |
-
else:
|
| 72 |
-
rating_text = f"{float(score):.1f} β"
|
| 73 |
|
| 74 |
# Language Logic
|
| 75 |
lang_val = row.get(lang_col, "N/A")
|
|
@@ -79,12 +70,7 @@ def search_apps(user_query):
|
|
| 79 |
except: pass
|
| 80 |
|
| 81 |
if isinstance(lang_val, list):
|
| 82 |
-
if len(lang_val) > 1
|
| 83 |
-
lang_text = f"{lang_val[0]} and more"
|
| 84 |
-
elif len(lang_val) == 1:
|
| 85 |
-
lang_text = str(lang_val[0])
|
| 86 |
-
else:
|
| 87 |
-
lang_text = "N/A"
|
| 88 |
else:
|
| 89 |
lang_text = str(lang_val)
|
| 90 |
|
|
@@ -98,41 +84,16 @@ def search_apps(user_query):
|
|
| 98 |
|
| 99 |
# Card HTML
|
| 100 |
card_html = f"""
|
| 101 |
-
<div style="
|
| 102 |
-
width: 280px;
|
| 103 |
-
padding: 20px;
|
| 104 |
-
background-color: white;
|
| 105 |
-
border: 1px solid #e5e7eb;
|
| 106 |
-
border-radius: 20px;
|
| 107 |
-
box-shadow: 0 10px 25px rgba(0,0,0,0.05);
|
| 108 |
-
display: flex;
|
| 109 |
-
flex-direction: column;
|
| 110 |
-
align-items: flex-start;
|
| 111 |
-
font-family: sans-serif;
|
| 112 |
-
">
|
| 113 |
{img_tag}
|
| 114 |
<h3 style="margin: 0 0 5px 0; color: #1f2937; font-size: 18px;">{row['trackName']}</h3>
|
| 115 |
<p style="margin: 0 0 10px 0; color: #6b7280; font-size: 14px; font-weight: 500;">{row['primaryGenreName']}</p>
|
| 116 |
-
|
| 117 |
<div style="display: flex; gap: 10px; margin-bottom: 10px; font-size: 13px; color: #4b5563;">
|
| 118 |
<span style="background: #f3f4f6; padding: 4px 8px; border-radius: 6px;">{rating_text}</span>
|
| 119 |
<span style="background: #f3f4f6; padding: 4px 8px; border-radius: 6px;">π£οΈ {lang_text}</span>
|
| 120 |
</div>
|
| 121 |
-
|
| 122 |
<p style="font-size: 13px; color: #6b7280; margin-bottom: 15px; line-height: 1.4;">{desc}</p>
|
| 123 |
-
|
| 124 |
-
<a href="{url}" target="_blank" style="
|
| 125 |
-
margin-top: auto;
|
| 126 |
-
width: 100%;
|
| 127 |
-
text-align: center;
|
| 128 |
-
background-color: #2563eb;
|
| 129 |
-
color: white;
|
| 130 |
-
padding: 10px 0;
|
| 131 |
-
border-radius: 10px;
|
| 132 |
-
text-decoration: none;
|
| 133 |
-
font-weight: bold;
|
| 134 |
-
transition: background 0.2s;
|
| 135 |
-
">Get App βοΈ</a>
|
| 136 |
</div>
|
| 137 |
"""
|
| 138 |
html_content += card_html
|
|
@@ -143,52 +104,43 @@ def search_apps(user_query):
|
|
| 143 |
except Exception as e:
|
| 144 |
return f"<div style='color:red;'>Error: {str(e)}</div>"
|
| 145 |
|
| 146 |
-
# --- 3. The UI (
|
| 147 |
-
with gr.Blocks(
|
| 148 |
|
| 149 |
gr.Markdown("# π± AI App Recommender")
|
| 150 |
gr.Markdown("Describe what you need, and the AI will find the best apps for you.")
|
| 151 |
|
| 152 |
-
# --- TABS START
|
| 153 |
with gr.Tabs():
|
| 154 |
|
| 155 |
-
#
|
| 156 |
with gr.Tab("π Find Apps"):
|
| 157 |
with gr.Column():
|
| 158 |
with gr.Row():
|
| 159 |
-
txt_input = gr.Textbox(
|
| 160 |
-
show_label=False,
|
| 161 |
-
placeholder="Type here... (e.g., 'I need a puzzle game for kids')",
|
| 162 |
-
scale=4
|
| 163 |
-
)
|
| 164 |
btn_submit = gr.Button("π Find Apps", variant="primary", scale=1)
|
| 165 |
|
| 166 |
-
gr.Examples(
|
| 167 |
-
examples=[["I want a timer for my kitchen"], ["A game to learn math"]],
|
| 168 |
-
inputs=txt_input
|
| 169 |
-
)
|
| 170 |
-
|
| 171 |
output_html = gr.HTML(label="Recommended Apps")
|
| 172 |
|
| 173 |
-
#
|
| 174 |
with gr.Tab("π₯ Video Presentation"):
|
| 175 |
gr.Markdown("### Watch our project presentation below:")
|
| 176 |
|
| 177 |
-
#
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
# --- FOOTER ---
|
| 182 |
-
gr.Markdown(
|
| 183 |
-
"""
|
| 184 |
-
<div style="text-align: center; margin-top: 40px; color: #9ca3af; font-size: 14px;">
|
| 185 |
-
app developed by Karin M & Lior F
|
| 186 |
-
</div>
|
| 187 |
-
"""
|
| 188 |
-
)
|
| 189 |
|
| 190 |
# Logic connection
|
| 191 |
btn_submit.click(fn=search_apps, inputs=txt_input, outputs=output_html)
|
| 192 |
txt_input.submit(fn=search_apps, inputs=txt_input, outputs=output_html)
|
| 193 |
|
|
|
|
| 194 |
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 23 |
lang_col = get_col_name(['languageCodesISO2A', 'primaryLanguage', 'languages', 'language'], df.columns)
|
| 24 |
rating_col = 'averageUserRating'
|
| 25 |
|
|
|
|
|
|
|
| 26 |
print("β³ Loading AI Model...")
|
| 27 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 28 |
print("β
Ready!")
|
|
|
|
| 43 |
top_results = df_results.sort_values(by="similarity_score", ascending=False).head(3)
|
| 44 |
|
| 45 |
# --- HTML GENERATION ---
|
|
|
|
|
|
|
| 46 |
html_content = """
|
| 47 |
<div style="margin-bottom: 20px; text-align: center;">
|
| 48 |
<h3 style="color: #374151; margin: 0;">Here is what our recommendation system found for you:</h3>
|
| 49 |
</div>
|
| 50 |
"""
|
|
|
|
|
|
|
| 51 |
html_content += '<div style="display: flex; gap: 20px; justify-content: center; flex-wrap: wrap;">'
|
| 52 |
|
| 53 |
for _, row in top_results.iterrows():
|
|
|
|
| 60 |
|
| 61 |
# Rating Logic
|
| 62 |
score = row.get(rating_col, 0)
|
| 63 |
+
rating_text = "No ratings yet" if (pd.isna(score) or score == 0) else f"{float(score):.1f} β"
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Language Logic
|
| 66 |
lang_val = row.get(lang_col, "N/A")
|
|
|
|
| 70 |
except: pass
|
| 71 |
|
| 72 |
if isinstance(lang_val, list):
|
| 73 |
+
lang_text = f"{lang_val[0]} and more" if len(lang_val) > 1 else (str(lang_val[0]) if len(lang_val) == 1 else "N/A")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
else:
|
| 75 |
lang_text = str(lang_val)
|
| 76 |
|
|
|
|
| 84 |
|
| 85 |
# Card HTML
|
| 86 |
card_html = f"""
|
| 87 |
+
<div style="width: 280px; padding: 20px; background-color: white; border: 1px solid #e5e7eb; border-radius: 20px; box-shadow: 0 10px 25px rgba(0,0,0,0.05); display: flex; flex-direction: column; align-items: flex-start; font-family: sans-serif;">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
{img_tag}
|
| 89 |
<h3 style="margin: 0 0 5px 0; color: #1f2937; font-size: 18px;">{row['trackName']}</h3>
|
| 90 |
<p style="margin: 0 0 10px 0; color: #6b7280; font-size: 14px; font-weight: 500;">{row['primaryGenreName']}</p>
|
|
|
|
| 91 |
<div style="display: flex; gap: 10px; margin-bottom: 10px; font-size: 13px; color: #4b5563;">
|
| 92 |
<span style="background: #f3f4f6; padding: 4px 8px; border-radius: 6px;">{rating_text}</span>
|
| 93 |
<span style="background: #f3f4f6; padding: 4px 8px; border-radius: 6px;">π£οΈ {lang_text}</span>
|
| 94 |
</div>
|
|
|
|
| 95 |
<p style="font-size: 13px; color: #6b7280; margin-bottom: 15px; line-height: 1.4;">{desc}</p>
|
| 96 |
+
<a href="{url}" target="_blank" style="margin-top: auto; width: 100%; text-align: center; background-color: #2563eb; color: white; padding: 10px 0; border-radius: 10px; text-decoration: none; font-weight: bold; transition: background 0.2s;">Get App βοΈ</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
</div>
|
| 98 |
"""
|
| 99 |
html_content += card_html
|
|
|
|
| 104 |
except Exception as e:
|
| 105 |
return f"<div style='color:red;'>Error: {str(e)}</div>"
|
| 106 |
|
| 107 |
+
# --- 3. The UI (Fixed Theme & Video Crash) ---
|
| 108 |
+
with gr.Blocks() as demo: # Removed theme from here (Fixes Warning)
|
| 109 |
|
| 110 |
gr.Markdown("# π± AI App Recommender")
|
| 111 |
gr.Markdown("Describe what you need, and the AI will find the best apps for you.")
|
| 112 |
|
| 113 |
+
# --- TABS START ---
|
| 114 |
with gr.Tabs():
|
| 115 |
|
| 116 |
+
# TAB 1: SEARCH
|
| 117 |
with gr.Tab("π Find Apps"):
|
| 118 |
with gr.Column():
|
| 119 |
with gr.Row():
|
| 120 |
+
txt_input = gr.Textbox(show_label=False, placeholder="Type here... (e.g., 'I need a puzzle game for kids')", scale=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
btn_submit = gr.Button("π Find Apps", variant="primary", scale=1)
|
| 122 |
|
| 123 |
+
gr.Examples(examples=[["I want a timer for my kitchen"], ["A game to learn math"]], inputs=txt_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
output_html = gr.HTML(label="Recommended Apps")
|
| 125 |
|
| 126 |
+
# TAB 2: VIDEO (Safe HTML Version)
|
| 127 |
with gr.Tab("π₯ Video Presentation"):
|
| 128 |
gr.Markdown("### Watch our project presentation below:")
|
| 129 |
|
| 130 |
+
# This is the "Safe" way that won't crash your app
|
| 131 |
+
gr.HTML("""
|
| 132 |
+
<video width="100%" controls>
|
| 133 |
+
<source src="https://huggingface.co/spaces/Liori25/ReccomendationSystemForApps/resolve/main/PresentationVideo.mp4" type="video/mp4">
|
| 134 |
+
Your browser does not support the video tag.
|
| 135 |
+
</video>
|
| 136 |
+
""")
|
| 137 |
|
| 138 |
# --- FOOTER ---
|
| 139 |
+
gr.Markdown("""<div style="text-align: center; margin-top: 40px; color: #9ca3af; font-size: 14px;">app developed by Karin M & Lior F</div>""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
# Logic connection
|
| 142 |
btn_submit.click(fn=search_apps, inputs=txt_input, outputs=output_html)
|
| 143 |
txt_input.submit(fn=search_apps, inputs=txt_input, outputs=output_html)
|
| 144 |
|
| 145 |
+
# --- Launch with Theme (Fixes Warning) ---
|
| 146 |
demo.launch(theme=gr.themes.Soft())
|