Spaces:
Runtime error
Runtime error
Update llm.py
Browse files
llm.py
CHANGED
@@ -1,23 +1,29 @@
|
|
1 |
-
from transformers import
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
def generate_answer(context, question):
|
7 |
prompt = f"""
|
8 |
-
You are a helpful
|
9 |
-
|
10 |
-
Context:
|
11 |
-
{context}
|
12 |
-
|
13 |
-
Question: {question}
|
14 |
-
|
15 |
-
Answer
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
do_sample=
|
|
|
|
|
22 |
)
|
23 |
-
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
|
3 |
+
qa_pipeline = pipeline(
|
4 |
+
"text2text-generation",
|
5 |
+
model="google/flan-t5-large",
|
6 |
+
device=0 if torch.cuda.is_available() else -1
|
7 |
+
)
|
8 |
|
9 |
def generate_answer(context, question):
|
10 |
prompt = f"""
|
11 |
+
You are a helpful research assistant. Use the context to answer the question.
|
12 |
+
|
13 |
+
Context:
|
14 |
+
{context}
|
15 |
+
|
16 |
+
Question: {question}
|
17 |
+
|
18 |
+
Answer in a comprehensive paragraph with key details:
|
19 |
+
"""
|
20 |
+
|
21 |
+
result = qa_pipeline(
|
22 |
+
prompt,
|
23 |
+
max_length=512,
|
24 |
+
do_sample=True,
|
25 |
+
temperature=0.7,
|
26 |
+
top_p=0.9
|
27 |
)
|
28 |
+
|
29 |
+
return result[0]['generated_text'].strip()
|