srikol commited on
Commit
80e95d4
·
verified ·
1 Parent(s): bddc9b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -44,7 +44,6 @@ def chunkify(t: str, max_tok: int = 180) -> List[str]:
44
  return out
45
 
46
  CHUNKS = chunkify(text)
47
-
48
  embedder = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
49
  vecs = embedder.encode(CHUNKS, convert_to_numpy=True)
50
  faiss.normalize_L2(vecs)
@@ -104,6 +103,22 @@ quick = [
104
  "Certifications","Skills","LinkedIn","Blog","Architecture"
105
  ]
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  with gr.Blocks(theme="soft") as demo:
108
  with gr.Row(equal_height=True):
109
  with gr.Column(min_width=170, scale=0):
@@ -113,24 +128,10 @@ with gr.Blocks(theme="soft") as demo:
113
  with gr.Column(scale=4):
114
  chat = gr.Chatbot(type="messages", label="SriGPT - Ask about my resume ", height=520)
115
  inp = gr.Textbox(placeholder="RAG based LM", show_label=False)
116
- state = gr.State([]) # Always a list!
117
-
118
- def user_submit(msg, hist):
119
- if hist is None: hist = []
120
- ans = generate(msg)
121
- hist = hist + [{"role":"user","content":msg},
122
- {"role":"assistant","content":ans}]
123
- return "", hist, hist # Must be: (string, list, list)
124
 
125
  inp.submit(user_submit, [inp, state], [inp, chat, state])
126
 
127
- def quick_send(hist, q):
128
- if hist is None: hist = []
129
- ans = generate(q)
130
- hist = hist + [{"role":"user","content":q},
131
- {"role":"assistant","content":ans}]
132
- return hist, hist # Must be: (list, list)
133
-
134
  for b, q in zip(btns, quick):
135
  b.click(lambda hist, q=q: quick_send(hist, q), [state], [chat, state])
136
 
 
44
  return out
45
 
46
  CHUNKS = chunkify(text)
 
47
  embedder = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
48
  vecs = embedder.encode(CHUNKS, convert_to_numpy=True)
49
  faiss.normalize_L2(vecs)
 
103
  "Certifications","Skills","LinkedIn","Blog","Architecture"
104
  ]
105
 
106
+ def user_submit(msg, hist):
107
+ if hist is None:
108
+ hist = []
109
+ ans = generate(msg)
110
+ hist = hist + [{"role":"user","content":msg},
111
+ {"role":"assistant","content":ans}]
112
+ return "", hist, hist
113
+
114
+ def quick_send(hist, q):
115
+ if hist is None:
116
+ hist = []
117
+ ans = generate(q)
118
+ hist = hist + [{"role":"user","content":q},
119
+ {"role":"assistant","content":ans}]
120
+ return hist, hist
121
+
122
  with gr.Blocks(theme="soft") as demo:
123
  with gr.Row(equal_height=True):
124
  with gr.Column(min_width=170, scale=0):
 
128
  with gr.Column(scale=4):
129
  chat = gr.Chatbot(type="messages", label="SriGPT - Ask about my resume ", height=520)
130
  inp = gr.Textbox(placeholder="RAG based LM", show_label=False)
131
+ state = gr.State([])
 
 
 
 
 
 
 
132
 
133
  inp.submit(user_submit, [inp, state], [inp, chat, state])
134
 
 
 
 
 
 
 
 
135
  for b, q in zip(btns, quick):
136
  b.click(lambda hist, q=q: quick_send(hist, q), [state], [chat, state])
137