GreatestParrot commited on
Commit
3789923
1 Parent(s): 8543f72
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.xlsx filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer, util
2
+ import numpy as np
3
+ import pandas as pd
4
+ import gradio as gr
5
+
6
+ #Load the model
7
+ model = SentenceTransformer('sentence-transformers/msmarco-bert-base-dot-v5')
8
+ doc_emb = pd.read_excel("proposals_emb.xlsx", usecols=lambda x: str(x).isnumeric())
9
+ df = pd.read_excel("proposals_clean.xlsx")
10
+
11
+
12
+ def cosine(u, v):
13
+ res = np.dot(u, v) / (np.linalg.norm(u) * np.linalg.norm(v))
14
+ return res
15
+
16
+
17
+ def form_link(post_id):
18
+ return f"https://kusama.polkassembly.io/referenda/{post_id}"
19
+
20
+
21
+ def processing(query):
22
+ query_emb = model.encode(query)
23
+ print(doc_emb.columns)
24
+ doc_emb['sim1'] = doc_emb.apply(lambda row: cosine(row, query_emb), axis=1)
25
+ sim = doc_emb.nlargest(5, 'sim1').index
26
+ res = df.iloc[sim][['content', 'status']]
27
+ doc_emb.drop(columns=["sim1"], inplace=True)
28
+
29
+ out = [f"[Proposal #{row[0]}]({form_link(row[0])}) - {row[1]['status']}: {ind+1}" for ind, row in enumerate(res.iterrows())]
30
+ markdown_string = ""
31
+ for i in range(len(out)):
32
+ markdown_string += f"{i+1}. {out[i]}\n"
33
+ return markdown_string
34
+
35
+
36
+ iface = gr.Interface(processing, "text", "markdown")
37
+ iface.launch()
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ name,output,flag,username,timestamp
2
+ sdafasdfasd,Hello sdafasdfasd!!,,,2023-11-07 14:09:04.894703
proposals_clean.xlsx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87e1dfc2c1655932b4970bc266770aac58c5f07956b96c8699b0198509847c3c
3
+ size 270107
proposals_emb.xlsx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2c3482a474475ca1e36a538c7b5957d66b6a10c7e801cf74616071750190dd4
3
+ size 3020034
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ sentence-transformers
2
+ pandas
3
+ numpy
4
+ gradio
5
+ openpyxl