dammy commited on
Commit
7ab093b
·
1 Parent(s): d121146

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -23
app.py CHANGED
@@ -12,17 +12,15 @@ import os
12
 
13
 
14
  model_name = 'google/flan-t5-base'
15
- model = T5ForConditionalGeneration.from_pretrained(model_name, device_map='auto', offload_folder="offload")
16
- tokenizer = AutoTokenizer.from_pretrained(model_name)
17
- print('flan read')
18
 
19
 
20
  ST_name = 'sentence-transformers/sentence-t5-base'
21
  st_model = SentenceTransformer(ST_name)
22
- print('sentence read')
23
 
24
  client = chromadb.Client()
25
- collection = client.create_collection("test_db")
26
 
27
 
28
  def get_context(query_text):
@@ -35,7 +33,7 @@ def get_context(query_text):
35
 
36
  def local_query(query, context):
37
  t5query = """Using the available context, please answer the question.
38
- If you aren't sure please say i don't know.
39
  Context: {}
40
  Question: {}
41
  """.format(context, query)
@@ -52,20 +50,9 @@ def local_query(query, context):
52
 
53
  def run_query(btn, history, query):
54
 
55
- context = get_context(query)
56
-
57
- print('calling local query')
58
- result = local_query(query, context)
59
-
60
-
61
- print('printing result after call back')
62
- print(result)
63
-
64
- history.append((query, str(result[0])))
65
-
66
-
67
- print('printing history')
68
- print(history)
69
  return history, ""
70
 
71
 
@@ -127,11 +114,9 @@ with gr.Blocks() as demo:
127
  # Event handler for uploading a PDF
128
  btn.upload(fn=upload_pdf, inputs=[btn], outputs=[output])
129
  txt.submit(run_query, [btn, chatbot, txt], [chatbot, txt])
130
- #.then(
131
- # generate_response, inputs =[chatbot,],outputs = chatbot,)
132
 
133
 
134
  gr.close_all()
135
- # demo.launch(share=True)
136
  demo.queue().launch()
137
 
 
12
 
13
 
14
  model_name = 'google/flan-t5-base'
15
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
16
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
 
17
 
18
 
19
  ST_name = 'sentence-transformers/sentence-t5-base'
20
  st_model = SentenceTransformer(ST_name)
 
21
 
22
  client = chromadb.Client()
23
+ collection = client.create_collection("my_database")
24
 
25
 
26
  def get_context(query_text):
 
33
 
34
  def local_query(query, context):
35
  t5query = """Using the available context, please answer the question.
36
+ If you are not sure please say I don't know.
37
  Context: {}
38
  Question: {}
39
  """.format(context, query)
 
50
 
51
  def run_query(btn, history, query):
52
 
53
+ context = get_context(query)
54
+ result = local_query(query, context)
55
+ history.append((query, str(result[0])))
 
 
 
 
 
 
 
 
 
 
 
56
  return history, ""
57
 
58
 
 
114
  # Event handler for uploading a PDF
115
  btn.upload(fn=upload_pdf, inputs=[btn], outputs=[output])
116
  txt.submit(run_query, [btn, chatbot, txt], [chatbot, txt])
 
 
117
 
118
 
119
  gr.close_all()
120
+
121
  demo.queue().launch()
122