Raphaël Bournhonesque commited on
Commit
6303e05
1 Parent(s): f19a6c4

update app

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -2,10 +2,21 @@ import requests
2
  import streamlit as st
3
 
4
 
 
 
 
 
 
 
 
 
 
 
 
5
  @st.cache_data
6
  def send_autocomplete_request(q: str, lang: str, taxonomy_names: list[str], size: int):
7
  return requests.get(
8
- "http://localhost:8000/autocomplete",
9
  params={
10
  "q": q,
11
  "lang": lang,
@@ -24,6 +35,8 @@ def run(
24
  response = send_autocomplete_request(query, lang, taxonomy_names, size)
25
  took = response["took"]
26
  timed_out = response["timed_out"]
 
 
27
  st.markdown(f"Took: {took} ms")
28
 
29
  if timed_out:
@@ -34,8 +47,10 @@ def run(
34
  {"text": o["text"], "id": o["id"], "taxonomy": o["taxonomy_name"]}
35
  for o in options
36
  ]
 
37
  st.table(options)
38
 
 
39
  st.write(response["debug"])
40
 
41
 
 
2
  import streamlit as st
3
 
4
 
5
+ ENV = "staging"
6
+
7
+ if ENV == "dev":
8
+ AUTOCOMPLETE_BASE_URL = "http://localhost:8000"
9
+ elif ENV == "staging":
10
+ AUTOCOMPLETE_BASE_URL = "https://off:off@search.openfoodfacts.net"
11
+ else:
12
+ AUTOCOMPLETE_BASE_URL = "https://search.openfoodfacts.org"
13
+
14
+ AUTOCOMPLETE_URL = f"{AUTOCOMPLETE_BASE_URL}/autocomplete"
15
+
16
  @st.cache_data
17
  def send_autocomplete_request(q: str, lang: str, taxonomy_names: list[str], size: int):
18
  return requests.get(
19
+ AUTOCOMPLETE_URL,
20
  params={
21
  "q": q,
22
  "lang": lang,
 
35
  response = send_autocomplete_request(query, lang, taxonomy_names, size)
36
  took = response["took"]
37
  timed_out = response["timed_out"]
38
+
39
+ st.markdown("---")
40
  st.markdown(f"Took: {took} ms")
41
 
42
  if timed_out:
 
47
  {"text": o["text"], "id": o["id"], "taxonomy": o["taxonomy_name"]}
48
  for o in options
49
  ]
50
+ st.markdown("### Results")
51
  st.table(options)
52
 
53
+ st.markdown("### Debug information")
54
  st.write(response["debug"])
55
 
56