Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 3 |
import torch
|
| 4 |
import spaces
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
model_name = "Qwen/Qwen2.5-0.5B-Instruct"
|
| 8 |
-
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
model_name,
|
|
@@ -23,7 +22,7 @@ pipe = pipeline(
|
|
| 23 |
do_sample=True
|
| 24 |
)
|
| 25 |
|
| 26 |
-
@spaces.GPU(duration=60)
|
| 27 |
def sales_agent(message):
|
| 28 |
prompt = f"""
|
| 29 |
You are a helpful pre-sales agent at Cotubex, a tech store in Brussels. Answer in the same language as the question.
|
|
@@ -42,14 +41,20 @@ Answer:
|
|
| 42 |
response = pipe(prompt)
|
| 43 |
return response[0]['generated_text'].replace(prompt, "").strip()
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
-
demo.launch(
|
|
|
|
| 3 |
import torch
|
| 4 |
import spaces
|
| 5 |
|
| 6 |
+
# Load model and tokenizer
|
| 7 |
model_name = "Qwen/Qwen2.5-0.5B-Instruct"
|
|
|
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
model_name,
|
|
|
|
| 22 |
do_sample=True
|
| 23 |
)
|
| 24 |
|
| 25 |
+
@spaces.GPU(duration=60)
|
| 26 |
def sales_agent(message):
|
| 27 |
prompt = f"""
|
| 28 |
You are a helpful pre-sales agent at Cotubex, a tech store in Brussels. Answer in the same language as the question.
|
|
|
|
| 41 |
response = pipe(prompt)
|
| 42 |
return response[0]['generated_text'].replace(prompt, "").strip()
|
| 43 |
|
| 44 |
+
# ChatInterface with default examples
|
| 45 |
+
examples = [
|
| 46 |
+
["Quel est le prix de la carte graphique Zotac 5060 TI ?"],
|
| 47 |
+
["Wat kost de Zotac 5060 TI videokaart?"],
|
| 48 |
+
["Is the Be Quiet water cooler available?"]
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
with gr.Blocks(css="style.css") as demo:
|
| 52 |
+
gr.Markdown("### Cotubex Pre-Sales Assistant π«π·π§πͺπ³π±\nAsk us anything about products, pricing, availability.")
|
| 53 |
+
gr.ChatInterface(
|
| 54 |
+
fn=sales_agent,
|
| 55 |
+
chatbot=gr.Chatbot(height=400, type="messages"),
|
| 56 |
+
examples=examples
|
| 57 |
+
)
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|