winfred2027 commited on
Commit
64fa430
1 Parent(s): 9145aca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -2
app.py CHANGED
@@ -1,4 +1,74 @@
1
  import streamlit as st
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+ st.title("TripletMix Demo")
4
+ st.caption("For faster inference without waiting in queue, you may clone the space and run it yourself.")
5
+ prog = st.progress(0.0, "Idle")
6
+ tab_cls, tab_img, tab_text, tab_pc, tab_sd, tab_cap = st.tabs([
7
+ "Classification",
8
+ "Retrieval w/ Image",
9
+ "Retrieval w/ Text",
10
+ "Retrieval w/ 3D",
11
+ "Image Generation",
12
+ "Captioning",
13
+ ])
14
+
15
+
16
+ def demo_classification():
17
+ with st.form("clsform"):
18
+ #load_data = misc_utils.input_3d_shape('cls')
19
+ cats = st.text_input("Custom Categories (64 max, separated with comma)")
20
+ cats = [a.strip() for a in cats.split(',')]
21
+ if len(cats) > 64:
22
+ st.error('Maximum 64 custom categories supported in the demo')
23
+ return
24
+ lvis_run = st.form_submit_button("Run Classification on LVIS Categories")
25
+ custom_run = st.form_submit_button("Run Classification on Custom Categories")
26
+ """
27
+ if lvis_run or auto_submit("clsauto"):
28
+ pc = load_data(prog)
29
+ col2 = misc_utils.render_pc(pc)
30
+ prog.progress(0.5, "Running Classification")
31
+ pred = classification.pred_lvis_sims(model_g14, pc)
32
+ with col2:
33
+ for i, (cat, sim) in zip(range(5), pred.items()):
34
+ st.text(cat)
35
+ st.caption("Similarity %.4f" % sim)
36
+ prog.progress(1.0, "Idle")
37
+ if custom_run:
38
+ pc = load_data(prog)
39
+ col2 = misc_utils.render_pc(pc)
40
+ prog.progress(0.5, "Computing Category Embeddings")
41
+ device = clip_model.device
42
+ tn = clip_prep(text=cats, return_tensors='pt', truncation=True, max_length=76, padding=True).to(device)
43
+ feats = clip_model.get_text_features(**tn).float().cpu()
44
+ prog.progress(0.5, "Running Classification")
45
+ pred = classification.pred_custom_sims(model_g14, pc, cats, feats)
46
+ with col2:
47
+ for i, (cat, sim) in zip(range(5), pred.items()):
48
+ st.text(cat)
49
+ st.caption("Similarity %.4f" % sim)
50
+ prog.progress(1.0, "Idle")
51
+ """
52
+ """
53
+ if image_examples(samples_index.classification, 3, example_text="Examples (Choose one of the following 3D shapes)"):
54
+ queue_auto_submit("clsauto")
55
+ """
56
+
57
+
58
+
59
+
60
+
61
+
62
+ try:
63
+ with tab_cls:
64
+ demo_classification()
65
+ """
66
+ with tab_cap:
67
+ demo_captioning()
68
+ with tab_sd:
69
+ demo_pc2img()
70
+ demo_retrieval()
71
+ """
72
+ except Exception:
73
+ import traceback
74
+ st.error(traceback.format_exc().replace("\n", " \n"))