Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
|
@@ -15,7 +22,15 @@ def respond(
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
for val in history:
|
| 21 |
if val[0]:
|
|
@@ -46,16 +61,13 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
additional_inputs=[
|
| 49 |
-
gr.Textbox(
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
Help troubleshoot common issues like warping, layer shifting, or nozzle clogs.
|
| 57 |
-
Share best practices for optimizing print quality and reducing waste.
|
| 58 |
-
Discuss innovations, trends, and applications in additive manufacturing.", label="System message"),
|
| 59 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 60 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 61 |
gr.Slider(
|
|
@@ -68,6 +80,5 @@ Discuss innovations, trends, and applications in additive manufacturing.", label
|
|
| 68 |
],
|
| 69 |
)
|
| 70 |
|
| 71 |
-
|
| 72 |
if __name__ == "__main__":
|
| 73 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Load knowledge base from a .txt file
|
| 5 |
+
def load_knowledge_base(file_path):
|
| 6 |
+
with open(file_path, "r") as file:
|
| 7 |
+
return file.read()
|
| 8 |
+
|
| 9 |
+
knowledge_base = load_knowledge_base("manufacturing_info.txt")
|
| 10 |
+
|
| 11 |
"""
|
| 12 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 13 |
"""
|
|
|
|
| 22 |
temperature,
|
| 23 |
top_p,
|
| 24 |
):
|
| 25 |
+
# Combine system message with knowledge base
|
| 26 |
+
system_message_with_knowledge = (
|
| 27 |
+
system_message
|
| 28 |
+
+ "\n\nKnowledge Base:\n"
|
| 29 |
+
+ knowledge_base
|
| 30 |
+
+ "\n\nRespond to the user's queries based on this knowledge."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
messages = [{"role": "system", "content": system_message_with_knowledge}]
|
| 34 |
|
| 35 |
for val in history:
|
| 36 |
if val[0]:
|
|
|
|
| 61 |
demo = gr.ChatInterface(
|
| 62 |
respond,
|
| 63 |
additional_inputs=[
|
| 64 |
+
gr.Textbox(
|
| 65 |
+
value=(
|
| 66 |
+
"You are AddiBot, an expert chatbot for additive manufacturing. "
|
| 67 |
+
"Assist users with all their 3D printing needs, using the knowledge base provided."
|
| 68 |
+
),
|
| 69 |
+
label="System message",
|
| 70 |
+
),
|
|
|
|
|
|
|
|
|
|
| 71 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 72 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 73 |
gr.Slider(
|
|
|
|
| 80 |
],
|
| 81 |
)
|
| 82 |
|
|
|
|
| 83 |
if __name__ == "__main__":
|
| 84 |
demo.launch()
|