ajsbsd commited on
Commit
064981c
Β·
verified Β·
1 Parent(s): 8028257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -3,9 +3,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
  import torch
4
  import spaces
5
 
6
- # Load tokenizer and model once at startup
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) # Use shared GPU for faster inference
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
- # Gradio Chat Interface
46
- demo = gr.ChatInterface(
47
- fn=sales_agent,
48
- chatbot=gr.Chatbot(height=400),
49
- additional_inputs=[],
50
- title="Cotubex Pre-Sales Assistant πŸ‡«πŸ‡·πŸ‡§πŸ‡ͺπŸ‡³πŸ‡±",
51
- description="Ask about product details, prices, availability β€” in French, Dutch, or English!"
52
- )
 
 
 
 
 
 
53
 
54
  if __name__ == "__main__":
55
- demo.launch(css="style.css")
 
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()