Spaces:
Runtime error
Runtime error
Commit
·
3dc9e1c
1
Parent(s):
78ad083
Update agent_t5.py
Browse files- agent_t5.py +10 -1
agent_t5.py
CHANGED
@@ -11,8 +11,10 @@ from transformers import AutoTokenizer, T5ForConditionalGeneration
|
|
11 |
from retrieval.retrieval import Retrieval, BM25
|
12 |
import os, time, torch
|
13 |
from torch.nn import Softmax
|
|
|
14 |
|
15 |
-
|
|
|
16 |
|
17 |
class Agent:
|
18 |
def __init__(self, args=None) -> None:
|
@@ -46,6 +48,13 @@ class Agent:
|
|
46 |
|
47 |
return f"Using file from {doc_path.name}"
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
def asking(self, question):
|
51 |
s_query = time.time()
|
|
|
11 |
from retrieval.retrieval import Retrieval, BM25
|
12 |
import os, time, torch
|
13 |
from torch.nn import Softmax
|
14 |
+
import requests
|
15 |
|
16 |
+
API_URL = "https://api-inference.huggingface.co/models/CreatorPhan/ViQA-small"
|
17 |
+
headers = {"Authorization": "Bearer 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"}
|
18 |
|
19 |
class Agent:
|
20 |
def __init__(self, args=None) -> None:
|
|
|
48 |
|
49 |
return f"Using file from {doc_path.name}"
|
50 |
|
51 |
+
def API_call(self, prompt):
|
52 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": prompt}).json()
|
53 |
+
if isinstance(response, list):
|
54 |
+
return response[0]['generated_text']
|
55 |
+
else:
|
56 |
+
time.sleep(3)
|
57 |
+
return self.API_call(prompt)
|
58 |
|
59 |
def asking(self, question):
|
60 |
s_query = time.time()
|