Spaces:
Runtime error
Runtime error
Jingxiang Mo
commited on
Commit
·
171f660
1
Parent(s):
d4e5967
API fix
Browse files- .env +1 -1
- __pycache__/app.cpython-39.pyc +0 -0
- app.py +2 -9
.env
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
OPENAI_API_KEY="sk-
|
|
|
|
| 1 |
+
OPENAI_API_KEY="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"
|
__pycache__/app.cpython-39.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-39.pyc and b/__pycache__/app.cpython-39.pyc differ
|
|
|
app.py
CHANGED
|
@@ -33,7 +33,6 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
|
|
| 33 |
)
|
| 34 |
return np.unique([result.get("word").strip() for result in results])
|
| 35 |
|
| 36 |
-
|
| 37 |
load_dotenv()
|
| 38 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 39 |
|
|
@@ -47,7 +46,6 @@ tokenizer = BertTokenizer.from_pretrained(
|
|
| 47 |
"bert-large-uncased-whole-word-masking-finetuned-squad"
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
| 51 |
def wikipedia_search(input: str) -> str:
|
| 52 |
"""Perform a Wikipedia search using keyphrases.
|
| 53 |
|
|
@@ -58,9 +56,7 @@ def wikipedia_search(input: str) -> str:
|
|
| 58 |
str: The summary of the Wikipedia page.
|
| 59 |
"""
|
| 60 |
|
| 61 |
-
|
| 62 |
-
keyphrases = extractor(input)
|
| 63 |
-
|
| 64 |
wiki = wk.Wikipedia("en")
|
| 65 |
|
| 66 |
try:
|
|
@@ -68,7 +64,7 @@ def wikipedia_search(input: str) -> str:
|
|
| 68 |
return "Can you add more details to your question?"
|
| 69 |
|
| 70 |
query_suggestion = wikipedia.suggest(keyphrases[0])
|
| 71 |
-
if query_suggestion
|
| 72 |
results = wikipedia.search(query_suggestion)
|
| 73 |
else:
|
| 74 |
results = wikipedia.search(keyphrases[0])
|
|
@@ -81,7 +77,6 @@ def wikipedia_search(input: str) -> str:
|
|
| 81 |
raise Exception
|
| 82 |
page = wiki.page(results[index])
|
| 83 |
return page.summary
|
| 84 |
-
|
| 85 |
except:
|
| 86 |
return "I cannot answer this question"
|
| 87 |
|
|
@@ -133,7 +128,6 @@ def answer_question(question: str) -> str:
|
|
| 133 |
- 1
|
| 134 |
]
|
| 135 |
)
|
| 136 |
-
|
| 137 |
scores = []
|
| 138 |
for input in input_ids_split:
|
| 139 |
# set Segment IDs
|
|
@@ -182,7 +176,6 @@ def answer_question(question: str) -> str:
|
|
| 182 |
)
|
| 183 |
return response.choices[0].text.replace("\n\n", " ")
|
| 184 |
|
| 185 |
-
|
| 186 |
# =====[ DEFINE INTERFACE ]===== #'
|
| 187 |
title = "Azza Knowledge Agent"
|
| 188 |
examples = [["Where is the Eiffel Tower?"], ["What is the population of France?"]]
|
|
|
|
| 33 |
)
|
| 34 |
return np.unique([result.get("word").strip() for result in results])
|
| 35 |
|
|
|
|
| 36 |
load_dotenv()
|
| 37 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 38 |
|
|
|
|
| 46 |
"bert-large-uncased-whole-word-masking-finetuned-squad"
|
| 47 |
)
|
| 48 |
|
|
|
|
| 49 |
def wikipedia_search(input: str) -> str:
|
| 50 |
"""Perform a Wikipedia search using keyphrases.
|
| 51 |
|
|
|
|
| 56 |
str: The summary of the Wikipedia page.
|
| 57 |
"""
|
| 58 |
|
| 59 |
+
keyphrases = extractor( input.replace("\n", " "))
|
|
|
|
|
|
|
| 60 |
wiki = wk.Wikipedia("en")
|
| 61 |
|
| 62 |
try:
|
|
|
|
| 64 |
return "Can you add more details to your question?"
|
| 65 |
|
| 66 |
query_suggestion = wikipedia.suggest(keyphrases[0])
|
| 67 |
+
if query_suggestion is not None:
|
| 68 |
results = wikipedia.search(query_suggestion)
|
| 69 |
else:
|
| 70 |
results = wikipedia.search(keyphrases[0])
|
|
|
|
| 77 |
raise Exception
|
| 78 |
page = wiki.page(results[index])
|
| 79 |
return page.summary
|
|
|
|
| 80 |
except:
|
| 81 |
return "I cannot answer this question"
|
| 82 |
|
|
|
|
| 128 |
- 1
|
| 129 |
]
|
| 130 |
)
|
|
|
|
| 131 |
scores = []
|
| 132 |
for input in input_ids_split:
|
| 133 |
# set Segment IDs
|
|
|
|
| 176 |
)
|
| 177 |
return response.choices[0].text.replace("\n\n", " ")
|
| 178 |
|
|
|
|
| 179 |
# =====[ DEFINE INTERFACE ]===== #'
|
| 180 |
title = "Azza Knowledge Agent"
|
| 181 |
examples = [["Where is the Eiffel Tower?"], ["What is the population of France?"]]
|