Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,8 +8,8 @@ import transformers # LLM
|
|
| 8 |
PUBLICATIONS_TO_RETRIEVE = 5
|
| 9 |
|
| 10 |
# The template for the RAG prompt
|
| 11 |
-
RAG_TEMPLATE = """You are an AI assistant who enjoys helping users learn about research.
|
| 12 |
-
Answer the USER_QUERY on additive manufacturing research using the RESEARCH_EXCERPTS.
|
| 13 |
Provide a concise ANSWER based on these excerpts. Avoid listing references.
|
| 14 |
===== RESEARCH_EXCERPTS =====
|
| 15 |
{research_excerpts}
|
|
@@ -18,6 +18,23 @@ Provide a concise ANSWER based on these excerpts. Avoid listing references.
|
|
| 18 |
===== ANSWER =====
|
| 19 |
"""
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Load vectorstore of SFF publications
|
| 22 |
publication_vectorstore = langchain_community.vectorstores.FAISS.load_local(
|
| 23 |
folder_path="publication_vectorstore",
|
|
@@ -30,13 +47,17 @@ publication_vectorstore = langchain_community.vectorstores.FAISS.load_local(
|
|
| 30 |
)
|
| 31 |
|
| 32 |
# Create the callable LLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
llm = transformers.pipeline(
|
| 34 |
task="text-generation",
|
| 35 |
-
model=
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
transformers.AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct-AWQ")
|
| 39 |
-
),
|
| 40 |
)
|
| 41 |
|
| 42 |
|
|
@@ -90,22 +111,6 @@ def reply(message: str, history: list[str]) -> str:
|
|
| 90 |
return response[0]["generated_text"].strip("= ")
|
| 91 |
|
| 92 |
|
| 93 |
-
# Example Queries for Interface
|
| 94 |
-
EXAMPLE_QUERIES = [
|
| 95 |
-
{"text": "What is multi-material 3D printing?"},
|
| 96 |
-
{"text": "How is additive manufacturing being applied in aerospace?"},
|
| 97 |
-
{"text": "Tell me about innovations in metal 3D printing techniques."},
|
| 98 |
-
{"text": "What are some sustainable materials for 3D printing?"},
|
| 99 |
-
{"text": "What are the challenges with support structures in 3D printing?"},
|
| 100 |
-
{"text": "How is 3D printing impacting the medical field?"},
|
| 101 |
-
{"text": "What are common applications of additive manufacturing in industry?"},
|
| 102 |
-
{"text": "What are the benefits and limitations of using polymers in 3D printing?"},
|
| 103 |
-
{"text": "Tell me about the environmental impacts of additive manufacturing."},
|
| 104 |
-
{"text": "What are the primary limitations of current 3D printing technologies?"},
|
| 105 |
-
{"text": "How are researchers improving the speed of 3D printing processes?"},
|
| 106 |
-
{"text": "What are best practices for post-processing in additive manufacturing?"},
|
| 107 |
-
]
|
| 108 |
-
|
| 109 |
# Run the Gradio Interface
|
| 110 |
gradio.ChatInterface(
|
| 111 |
reply,
|
|
|
|
| 8 |
PUBLICATIONS_TO_RETRIEVE = 5
|
| 9 |
|
| 10 |
# The template for the RAG prompt
|
| 11 |
+
RAG_TEMPLATE = """You are an AI assistant who enjoys helping users learn about research.
|
| 12 |
+
Answer the USER_QUERY on additive manufacturing research using the RESEARCH_EXCERPTS.
|
| 13 |
Provide a concise ANSWER based on these excerpts. Avoid listing references.
|
| 14 |
===== RESEARCH_EXCERPTS =====
|
| 15 |
{research_excerpts}
|
|
|
|
| 18 |
===== ANSWER =====
|
| 19 |
"""
|
| 20 |
|
| 21 |
+
# Example Queries for Interface
|
| 22 |
+
EXAMPLE_QUERIES = [
|
| 23 |
+
{"text": "What is multi-material 3D printing?"},
|
| 24 |
+
{"text": "How is additive manufacturing being applied in aerospace?"},
|
| 25 |
+
{"text": "Tell me about innovations in metal 3D printing techniques."},
|
| 26 |
+
{"text": "What are some sustainable materials for 3D printing?"},
|
| 27 |
+
{"text": "What are the challenges with support structures in 3D printing?"},
|
| 28 |
+
{"text": "How is 3D printing impacting the medical field?"},
|
| 29 |
+
{"text": "What are common applications of additive manufacturing in industry?"},
|
| 30 |
+
{"text": "What are the benefits and limitations of using polymers in 3D printing?"},
|
| 31 |
+
{"text": "Tell me about the environmental impacts of additive manufacturing."},
|
| 32 |
+
{"text": "What are the primary limitations of current 3D printing technologies?"},
|
| 33 |
+
{"text": "How are researchers improving the speed of 3D printing processes?"},
|
| 34 |
+
{"text": "What are best practices for post-processing in additive manufacturing?"},
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
# Load vectorstore of SFF publications
|
| 39 |
publication_vectorstore = langchain_community.vectorstores.FAISS.load_local(
|
| 40 |
folder_path="publication_vectorstore",
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
# Create the callable LLM
|
| 50 |
+
model = transformers.AutoModelForCausalLM.from_pretrained(
|
| 51 |
+
"Qwen/Qwen2.5-7B-Instruct-AWQ"
|
| 52 |
+
)
|
| 53 |
+
model.to("cuda") # Move the model to GPU
|
| 54 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct-AWQ")
|
| 55 |
+
|
| 56 |
llm = transformers.pipeline(
|
| 57 |
task="text-generation",
|
| 58 |
+
model=model,
|
| 59 |
+
tokenizer=tokenizer,
|
| 60 |
+
device=0, # Ensure the model is loaded on the GPU
|
|
|
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
|
|
|
|
| 111 |
return response[0]["generated_text"].strip("= ")
|
| 112 |
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
# Run the Gradio Interface
|
| 115 |
gradio.ChatInterface(
|
| 116 |
reply,
|