Update app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,7 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
17 |
trust_remote_code=True,
|
18 |
)
|
19 |
|
|
|
20 |
@spaces.GPU(duration=300)
|
21 |
def generate_response(query):
|
22 |
# π generate_response ν¨μ μμμ λ§€λ² λ‘λ
|
@@ -58,9 +59,23 @@ def generate_response(query):
|
|
58 |
|
59 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
60 |
|
|
|
61 |
@spaces.GPU(duration=300)
|
62 |
def generate_response_with_pipeline(query):
|
63 |
-
return rag_pipeline(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
demo = gr.Interface(fn=
|
66 |
demo.launch()
|
|
|
17 |
trust_remote_code=True,
|
18 |
)
|
19 |
|
20 |
+
# v0
|
21 |
@spaces.GPU(duration=300)
|
22 |
def generate_response(query):
|
23 |
# π generate_response ν¨μ μμμ λ§€λ² λ‘λ
|
|
|
59 |
|
60 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
61 |
|
62 |
+
# v1
|
63 |
@spaces.GPU(duration=300)
|
64 |
def generate_response_with_pipeline(query):
|
65 |
+
return rag_pipeline(query)
|
66 |
+
|
67 |
+
# v2
|
68 |
+
search_cache = {}
|
69 |
+
@spaces.GPU(duration=300)
|
70 |
+
def search_documents_with_cache(query: str):
|
71 |
+
if query in search_cache:
|
72 |
+
print(f"β‘ μΊμ μ¬μ©: '{query}'")
|
73 |
+
return search_cache[query]
|
74 |
+
|
75 |
+
results = rag_pipeline(query)
|
76 |
+
search_cache[query] = results
|
77 |
+
return results
|
78 |
+
|
79 |
|
80 |
+
demo = gr.Interface(fn=search_documents_with_cache, inputs="text", outputs="text")
|
81 |
demo.launch()
|