faisalsns commited on
Commit
68fc69b
·
verified ·
1 Parent(s): 7cfac1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -10
app.py CHANGED
@@ -23,19 +23,44 @@ def submit_feedback(app_id, rating, comment):
23
  "Content-Type": "application/json"
24
  }
25
  r = requests.post(f"{SUPABASE_URL}/rest/v1/{TABLE_NAME}", json=payload, headers=headers)
26
- if r.status_code == 201:
27
- return "Thank you for your feedback!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  else:
29
- return f"Error: {r.status_code} - {r.text}"
30
 
31
  with gr.Blocks() as demo:
32
- gr.Markdown("### Rate this app")
33
- app_id = gr.Textbox(label="App ID", placeholder="e.g., app123")
34
- rating = gr.Slider(minimum=1, maximum=5, step=1, label="Rating")
35
- comment = gr.Textbox(lines=4, label="Comment")
36
- output = gr.Textbox(label="Status", interactive=False)
37
- submit_btn = gr.Button("Submit")
 
 
38
 
39
- submit_btn.click(fn=submit_feedback, inputs=[app_id, rating, comment], outputs=[output])
 
 
 
 
 
 
 
40
 
41
  demo.launch()
 
23
  "Content-Type": "application/json"
24
  }
25
  r = requests.post(f"{SUPABASE_URL}/rest/v1/{TABLE_NAME}", json=payload, headers=headers)
26
+ return "Thank you!" if r.status_code == 201 else f"Error: {r.status_code}"
27
+
28
+ def fetch_feedback(app_filter, pwd):
29
+ if pwd != ADMIN_PASSWORD:
30
+ return "Unauthorized", []
31
+ headers = {
32
+ "apikey": SUPABASE_KEY,
33
+ "Authorization": f"Bearer {SUPABASE_KEY}"
34
+ }
35
+ query = f"?select=app_id,rating,comment,created_at&order=created_at.desc"
36
+ if app_filter:
37
+ query += f"&app_id=eq.{app_filter}"
38
+ url = f"{SUPABASE_URL}/rest/v1/{TABLE_NAME}{query}"
39
+ r = requests.get(url, headers=headers)
40
+ if r.status_code == 200:
41
+ data = r.json()
42
+ rows = [[d["app_id"], d["rating"], d["comment"], d["created_at"]] for d in data]
43
+ return f"{len(rows)} entries", rows
44
  else:
45
+ return f"Error: {r.status_code}", []
46
 
47
  with gr.Blocks() as demo:
48
+ with gr.Tab("Feedback Form"):
49
+ gr.Markdown("### Rate this app")
50
+ app_id = gr.Textbox(label="App ID")
51
+ rating = gr.Slider(minimum=1, maximum=5, step=1, label="Rating")
52
+ comment = gr.Textbox(label="Comment", lines=4)
53
+ output = gr.Textbox(label="Status", interactive=False)
54
+ submit_btn = gr.Button("Submit")
55
+ submit_btn.click(fn=submit_feedback, inputs=[app_id, rating, comment], outputs=[output])
56
 
57
+ with gr.Tab("Admin Panel"):
58
+ gr.Markdown("### View Feedback (Admin Only)")
59
+ pwd = gr.Textbox(label="Admin Password", type="password")
60
+ app_filter = gr.Textbox(label="Filter by App ID (optional)")
61
+ status = gr.Textbox(label="Status")
62
+ table = gr.Dataframe(headers=["App ID", "Rating", "Comment", "Timestamp"], interactive=False)
63
+ view_btn = gr.Button("Load Feedback")
64
+ view_btn.click(fn=fetch_feedback, inputs=[app_filter, pwd], outputs=[status, table])
65
 
66
  demo.launch()