Spaces:
Runtime error
Runtime error
next test
Browse files- README.md +1 -1
- app.py +49 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 😻
|
|
4 |
colorFrom: green
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: green
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.39.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import Stemmer # from PyStemmer
|
3 |
+
import bm25s
|
4 |
+
import numpy as np
|
5 |
+
import time
|
6 |
+
import os
|
7 |
+
|
8 |
+
examples = ["Can officers always order a passenger out of a car?","Find me briefs about credential searches", "Can police search an impounded car without a warrant?", "State is arguing State v. Carty is not good law"]
|
9 |
+
|
10 |
+
def show_user_query(user_message, history):
|
11 |
+
return "", history + [[user_message, None]]
|
12 |
+
|
13 |
+
def retrieve(history):
|
14 |
+
query = history[-1][0]
|
15 |
+
print ("query", query)
|
16 |
+
query_tokens = bm25s.tokenize(query, stemmer=stemmer)
|
17 |
+
|
18 |
+
results, scores = retriever.retrieve(query_tokens, k=10)
|
19 |
+
query_response = " ".join([str(i) for i in results])
|
20 |
+
#query_response = retrieve(history[-1][0])
|
21 |
+
#print (query_response)
|
22 |
+
history[-1][1] = ""
|
23 |
+
for character in query_response:
|
24 |
+
history[-1][1] += character
|
25 |
+
time.sleep(0.0001)
|
26 |
+
yield history
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
#gr.LoginButton()
|
32 |
+
chatbot = gr.Chatbot()
|
33 |
+
query_textbox = gr.Textbox()
|
34 |
+
examples = gr.Examples(examples, query_textbox)
|
35 |
+
next_button = gr.ClearButton(chatbot, value="Clear", visible=True)
|
36 |
+
|
37 |
+
query_textbox.submit(show_user_query, [query_textbox, chatbot], [query_textbox, chatbot], queue=False).then(retrieve, chatbot, chatbot)
|
38 |
+
|
39 |
+
|
40 |
+
def load_bm25():
|
41 |
+
stemmer = Stemmer.Stemmer("english")
|
42 |
+
retriever = bm25s.BM25.load("NJ_index_LLM_chunking", mmap=False)
|
43 |
+
return retriever, stemmer
|
44 |
+
|
45 |
+
retriever, stemmer = load_bm25()
|
46 |
+
#demo.launch(share=True, auth=(os.environ.get("username"), os.environ.get("password")))
|
47 |
+
#demo.launch(auth=("admin", "pass1234"))
|
48 |
+
|
49 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
bm25s
|
2 |
+
PyStemmer
|
3 |
+
https://gradio-builds.s3.amazonaws.com/4485dd46a8e4b3f5b35e42d52f291b72fdc1a952/gradio-4.39.0-py3-none-any.whl
|