dasomaru commited on
Commit
ccfdfe2
Β·
verified Β·
1 Parent(s): b8c3699

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
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=generate_response_with_pipeline, inputs="text", outputs="text")
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()