Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import threading # to allow streaming response
|
| 2 |
-
import time # to pave the deliver of the message
|
| 3 |
|
| 4 |
import gradio # for the interface
|
| 5 |
import spaces # for GPU
|
|
@@ -76,18 +75,16 @@ chatmodel = transformers.AutoModelForCausalLM.from_pretrained(
|
|
| 76 |
)
|
| 77 |
|
| 78 |
|
| 79 |
-
def preprocess(query: str, k: int) ->
|
| 80 |
"""
|
| 81 |
Searches the dataset for the top k most relevant papers to the query and returns a prompt and references
|
| 82 |
Args:
|
| 83 |
query (str): The user's query
|
| 84 |
k (int): The number of results to return
|
| 85 |
Returns:
|
| 86 |
-
|
| 87 |
"""
|
| 88 |
-
documents = publication_vectorstore.search(
|
| 89 |
-
query, k=PUBLICATIONS_TO_RETRIEVE, search_type="similarity"
|
| 90 |
-
)
|
| 91 |
|
| 92 |
prompt = (
|
| 93 |
"You are an AI assistant who delights in helping people learn about research. "
|
|
@@ -109,7 +106,7 @@ def preprocess(query: str, k: int) -> tuple[str, str]:
|
|
| 109 |
|
| 110 |
print(prompt)
|
| 111 |
|
| 112 |
-
return prompt
|
| 113 |
|
| 114 |
|
| 115 |
@spaces.GPU
|
|
@@ -124,7 +121,7 @@ def reply(message: str, history: list[str]) -> str:
|
|
| 124 |
"""
|
| 125 |
|
| 126 |
# Apply preprocessing
|
| 127 |
-
message
|
| 128 |
|
| 129 |
# This is some handling that is applied to the history variable to put it in a good format
|
| 130 |
history_transformer_format = [
|
|
@@ -150,6 +147,7 @@ def reply(message: str, history: list[str]) -> str:
|
|
| 150 |
partial_message += new_token
|
| 151 |
yield partial_message
|
| 152 |
|
|
|
|
| 153 |
# Example queries
|
| 154 |
EXAMPLE_QUERIES = [
|
| 155 |
"What is multi-material 3D printing?",
|
|
@@ -162,7 +160,6 @@ EXAMPLE_QUERIES = [
|
|
| 162 |
"What are the benefits and limitations of using polymers in 3D printing?",
|
| 163 |
"Tell me about the environmental impacts of additive manufacturing.",
|
| 164 |
"What are the primary limitations of current 3D printing technologies?",
|
| 165 |
-
"What future trends are expected in the field of additive manufacturing?",
|
| 166 |
"How are researchers improving the speed of 3D printing processes?",
|
| 167 |
"What are the best practices for managing post-processing in additive manufacturing?",
|
| 168 |
]
|
|
|
|
| 1 |
import threading # to allow streaming response
|
|
|
|
| 2 |
|
| 3 |
import gradio # for the interface
|
| 4 |
import spaces # for GPU
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
|
| 78 |
+
def preprocess(query: str, k: int) -> str:
|
| 79 |
"""
|
| 80 |
Searches the dataset for the top k most relevant papers to the query and returns a prompt and references
|
| 81 |
Args:
|
| 82 |
query (str): The user's query
|
| 83 |
k (int): The number of results to return
|
| 84 |
Returns:
|
| 85 |
+
str: The prompt to be used for the AI
|
| 86 |
"""
|
| 87 |
+
documents = publication_vectorstore.search(query, k=k, search_type="similarity")
|
|
|
|
|
|
|
| 88 |
|
| 89 |
prompt = (
|
| 90 |
"You are an AI assistant who delights in helping people learn about research. "
|
|
|
|
| 106 |
|
| 107 |
print(prompt)
|
| 108 |
|
| 109 |
+
return prompt
|
| 110 |
|
| 111 |
|
| 112 |
@spaces.GPU
|
|
|
|
| 121 |
"""
|
| 122 |
|
| 123 |
# Apply preprocessing
|
| 124 |
+
message = preprocess(message, PUBLICATIONS_TO_RETRIEVE)
|
| 125 |
|
| 126 |
# This is some handling that is applied to the history variable to put it in a good format
|
| 127 |
history_transformer_format = [
|
|
|
|
| 147 |
partial_message += new_token
|
| 148 |
yield partial_message
|
| 149 |
|
| 150 |
+
|
| 151 |
# Example queries
|
| 152 |
EXAMPLE_QUERIES = [
|
| 153 |
"What is multi-material 3D printing?",
|
|
|
|
| 160 |
"What are the benefits and limitations of using polymers in 3D printing?",
|
| 161 |
"Tell me about the environmental impacts of additive manufacturing.",
|
| 162 |
"What are the primary limitations of current 3D printing technologies?",
|
|
|
|
| 163 |
"How are researchers improving the speed of 3D printing processes?",
|
| 164 |
"What are the best practices for managing post-processing in additive manufacturing?",
|
| 165 |
]
|