Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import os
|
|
|
|
|
|
|
2 |
import threading
|
3 |
import torch
|
4 |
import torch._dynamo
|
@@ -15,19 +18,26 @@ from docx import Document
|
|
15 |
|
16 |
|
17 |
SYSTEM_PROMPT = """
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
"""
|
21 |
|
22 |
-
|
23 |
-
MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
24 |
|
25 |
|
26 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
27 |
model = AutoModelForCausalLM.from_pretrained(
|
28 |
MODEL_ID,
|
29 |
torch_dtype=torch.bfloat16,
|
30 |
-
device_map="auto"
|
|
|
31 |
)
|
32 |
|
33 |
print(f"Model loaded on device: {model.device}")
|
@@ -63,10 +73,6 @@ def respond(
|
|
63 |
temperature: float,
|
64 |
top_p: float,
|
65 |
):
|
66 |
-
greetings = {"hi", "hello", "hey", "hey there", "good morning"}
|
67 |
-
if message.strip().lower() in greetings:
|
68 |
-
yield "Hi there! 👋 Welcome to Café Eleven. Would you like help placing an order?"
|
69 |
-
return
|
70 |
context = retrieve_context(message)
|
71 |
|
72 |
messages = [{"role": "system", "content": system_message}]
|
@@ -101,6 +107,7 @@ def respond(
|
|
101 |
response += new_text
|
102 |
yield response
|
103 |
|
|
|
104 |
demo = gr.ChatInterface(
|
105 |
fn=respond,
|
106 |
title="Café Eleven Assistant",
|
|
|
1 |
import os
|
2 |
+
os.system("pip install git+https://github.com/shumingma/transformers.git")
|
3 |
+
os.system("pip install python-docx")
|
4 |
+
|
5 |
import threading
|
6 |
import torch
|
7 |
import torch._dynamo
|
|
|
18 |
|
19 |
|
20 |
SYSTEM_PROMPT = """
|
21 |
+
You are a friendly café assistant for Café Eleven. Your job is to:
|
22 |
+
1. Greet the customer warmly.
|
23 |
+
2. Help them order food and drinks from our menu.
|
24 |
+
3. Ask the customer for their desired pickup time.
|
25 |
+
4. Confirm the pickup time before ending the conversation.
|
26 |
+
5. Answer questions about ingredients, preparation, etc.
|
27 |
+
6. Handle special requests (allergies, modifications) politely.
|
28 |
+
7. Provide calorie information if asked.
|
29 |
+
Always be polite, helpful, and ensure the customer feels welcomed and cared for!
|
30 |
"""
|
31 |
|
32 |
+
MODEL_ID = "microsoft/bitnet-b1.58-2B-4T"
|
|
|
33 |
|
34 |
|
35 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
36 |
model = AutoModelForCausalLM.from_pretrained(
|
37 |
MODEL_ID,
|
38 |
torch_dtype=torch.bfloat16,
|
39 |
+
device_map="auto",
|
40 |
+
trust_remote_code=True
|
41 |
)
|
42 |
|
43 |
print(f"Model loaded on device: {model.device}")
|
|
|
73 |
temperature: float,
|
74 |
top_p: float,
|
75 |
):
|
|
|
|
|
|
|
|
|
76 |
context = retrieve_context(message)
|
77 |
|
78 |
messages = [{"role": "system", "content": system_message}]
|
|
|
107 |
response += new_text
|
108 |
yield response
|
109 |
|
110 |
+
|
111 |
demo = gr.ChatInterface(
|
112 |
fn=respond,
|
113 |
title="Café Eleven Assistant",
|