Update app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,12 @@ embed_model = SentenceTransformer(
|
|
| 10 |
"sentence-transformers/all-MiniLM-L6-v2"
|
| 11 |
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
chunks_store=[]
|
|
@@ -62,7 +64,7 @@ def ask_question(question):
|
|
| 62 |
)
|
| 63 |
|
| 64 |
prompt=f"""
|
| 65 |
-
|
| 66 |
|
| 67 |
Context:
|
| 68 |
{retrieved}
|
|
@@ -73,13 +75,25 @@ Question:
|
|
| 73 |
Answer:
|
| 74 |
"""
|
| 75 |
|
| 76 |
-
|
| 77 |
prompt,
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
with gr.Blocks() as demo:
|
|
|
|
| 10 |
"sentence-transformers/all-MiniLM-L6-v2"
|
| 11 |
)
|
| 12 |
|
| 13 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 14 |
+
|
| 15 |
+
gen_model_name="google/flan-t5-base"
|
| 16 |
+
|
| 17 |
+
gen_tokenizer=AutoTokenizer.from_pretrained(gen_model_name)
|
| 18 |
+
gen_model=AutoModelForSeq2SeqLM.from_pretrained(gen_model_name)
|
| 19 |
|
| 20 |
|
| 21 |
chunks_store=[]
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
prompt=f"""
|
| 67 |
+
Answer the question only using the context.
|
| 68 |
|
| 69 |
Context:
|
| 70 |
{retrieved}
|
|
|
|
| 75 |
Answer:
|
| 76 |
"""
|
| 77 |
|
| 78 |
+
inputs=gen_tokenizer(
|
| 79 |
prompt,
|
| 80 |
+
return_tensors="pt",
|
| 81 |
+
truncation=True,
|
| 82 |
+
max_length=512
|
| 83 |
+
)
|
| 84 |
|
| 85 |
+
outputs=gen_model.generate(
|
| 86 |
+
**inputs,
|
| 87 |
+
max_new_tokens=120,
|
| 88 |
+
num_beams=4
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
answer=gen_tokenizer.decode(
|
| 92 |
+
outputs[0],
|
| 93 |
+
skip_special_tokens=True
|
| 94 |
+
)
|
| 95 |
|
| 96 |
+
return answer,retrieved
|
| 97 |
|
| 98 |
|
| 99 |
with gr.Blocks() as demo:
|