Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
-
from transformers import RagRetriever, RagTokenizer
|
4 |
|
5 |
"""
|
6 |
For more information on huggingface_hub Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
-
# Load the RAG tokenizer
|
11 |
tokenizer = RagTokenizer.from_pretrained("deepset/roberta-base-squad2")
|
12 |
-
retriever = RagRetriever.from_pretrained("deepset/roberta-base-squad2", index_name="apexcustoms", passages="apexcustoms.pdf")
|
13 |
-
|
|
|
|
|
14 |
|
15 |
def respond(
|
16 |
message,
|
@@ -40,7 +42,7 @@ def respond(
|
|
40 |
top_p=top_p,
|
41 |
rag_retriever=retriever, # Pass the RAG retriever
|
42 |
rag_tokenizer=tokenizer, # Pass the RAG tokenizer
|
43 |
-
|
44 |
):
|
45 |
token = message.choices[0].delta.content
|
46 |
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
from transformers import pipeline, RagRetriever, RagTokenizer
|
4 |
|
5 |
"""
|
6 |
For more information on huggingface_hub Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
+
# Load the RAG tokenizer and retriever
|
11 |
tokenizer = RagTokenizer.from_pretrained("deepset/roberta-base-squad2")
|
12 |
+
retriever = RagRetriever.from_pretrained("deepset/roberta-base-squad2", index_name="apexcustoms", passages="apexcustoms.pdf", trust_remote_code=True)
|
13 |
+
|
14 |
+
# Load the question-answering pipeline
|
15 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2", tokenizer=tokenizer)
|
16 |
|
17 |
def respond(
|
18 |
message,
|
|
|
42 |
top_p=top_p,
|
43 |
rag_retriever=retriever, # Pass the RAG retriever
|
44 |
rag_tokenizer=tokenizer, # Pass the RAG tokenizer
|
45 |
+
rag_pipeline=qa_pipeline, # Pass the question-answering pipeline
|
46 |
):
|
47 |
token = message.choices[0].delta.content
|
48 |
|