1TSnakers commited on
Commit
159caed
·
verified ·
1 Parent(s): 24c42d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -34
app.py CHANGED
@@ -10,39 +10,25 @@ st.header("List Ollama model downloads")
10
  HOST = os.getenv("HOST", "https://1tsnakers-ollamasearchapi.hf.space")
11
 
12
  def is_api_up():
13
-
14
- r = requests.get(f"{HOST}/ping")
15
-
16
- return r.status_code == 200
 
17
 
18
  if st.button("Make list"):
19
  start_time = time.time()
 
20
  if not is_api_up():
21
- st.error(f"HTTP error {r.status_code}")
22
  else:
23
  r = requests.get(f"{HOST}/library")
 
24
 
25
- library = r.json()
26
- library = library["results"]
27
-
28
- # add model data
29
- models = []
30
- for model in library:
31
- models.append(model["model_base_name"])
32
-
33
- # add pull count
34
- pull_count = []
35
- for model in library:
36
- pull_count.append(int(model["pull_count"]))
37
-
38
- pull_count_str = []
39
- for model in library:
40
- pull_count_str.append(model["pull_count_str"])
41
-
42
- # add date updated
43
- date = []
44
- for model in library:
45
- date.append(datetime.fromisoformat(model["last_updated_iso"]))
46
 
47
  df = pd.DataFrame({
48
  "model": models,
@@ -50,19 +36,16 @@ if st.button("Make list"):
50
  "pull_count_str": pull_count_str,
51
  "date": date
52
  })
53
- end_time = time.time()
54
- elapsed_time = end_time - start_time
55
-
56
  st.write(f"{len(models)} models counted in {elapsed_time:.4f} seconds")
57
 
58
  st.dataframe(
59
- dfstyle.format({"pull_count": lambda x, i=None: pull_count_str[i]}),
60
  hide_index=True,
61
  column_config={
62
- "name": "AI Model",
63
  "pull_count_str": "Pulls",
64
- "date": st.column_config.DateColumn(
65
- "Last Updated"
66
- )
67
  }
68
  )
 
10
  HOST = os.getenv("HOST", "https://1tsnakers-ollamasearchapi.hf.space")
11
 
12
  def is_api_up():
13
+ try:
14
+ r = requests.get(f"{HOST}/ping")
15
+ return r.status_code == 200
16
+ except:
17
+ return False
18
 
19
  if st.button("Make list"):
20
  start_time = time.time()
21
+
22
  if not is_api_up():
23
+ st.error("API is not reachable")
24
  else:
25
  r = requests.get(f"{HOST}/library")
26
+ library = r.json()["results"]
27
 
28
+ models = [model["model_base_name"] for model in library]
29
+ pull_count = [int(model["pull_count"]) for model in library]
30
+ pull_count_str = [model["pull_count_str"] for model in library]
31
+ date = [datetime.fromisoformat(model["last_updated_iso"]) for model in library]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  df = pd.DataFrame({
34
  "model": models,
 
36
  "pull_count_str": pull_count_str,
37
  "date": date
38
  })
39
+
40
+ elapsed_time = time.time() - start_time
 
41
  st.write(f"{len(models)} models counted in {elapsed_time:.4f} seconds")
42
 
43
  st.dataframe(
44
+ df[["model", "pull_count_str", "date"]],
45
  hide_index=True,
46
  column_config={
47
+ "model": "AI Model",
48
  "pull_count_str": "Pulls",
49
+ "date": st.column_config.DateColumn("Last Updated")
 
 
50
  }
51
  )