eduard76 commited on
Commit
5754868
·
verified ·
1 Parent(s): 8aa7a71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -1,28 +1,20 @@
1
- from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, pipeline
2
  import torch
3
  import gradio as gr
4
 
5
  model_id = "eduard76/Llama3-8b-good-new"
6
 
7
- #quant_config = BitsAndBytesConfig(
8
- # load_in_4bit=True,
9
- # bnb_4bit_compute_dtype=torch.float16,
10
- # bnb_4bit_use_double_quant=True,
11
- # bnb_4bit_quant_type="nf4"
12
- #)
13
-
14
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
 
15
  model = AutoModelForCausalLM.from_pretrained(
16
  model_id,
17
- device_map="auto",
18
- #torch_dtype=torch.float16,
19
- quantization_config=quant_config,
20
  trust_remote_code=True
21
  )
22
 
23
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
24
 
25
- # 🔐 Lista de topicuri din dataset (poți ajusta manual dacă vrei):
26
  covered_topics = {
27
  "ospf", "bgp", "eigrp", "vxlan", "evpn", "network design", "acl", "routing",
28
  "spine", "leaf", "underlay", "overlay", "mpls", "qos", "firewall",
@@ -32,7 +24,7 @@ covered_topics = {
32
  def chat(user_input):
33
  prompt = f"""You are a Cisco-certified network architect trained in OSPF, BGP, EIGRP, VLAN, STP, RSTP design principles.
34
  If the user's question is unclear, clarify first.
35
- If the topic is outside OSPF, BGP, EIGRP, VLAN, STP, RSTP, respond with: "I'm not trained on that topic."
36
  Give short, clear, non-repetitive answers.
37
 
38
  User: {user_input}
@@ -51,7 +43,6 @@ AI:"""
51
 
52
  return response[len(prompt):].strip()
53
 
54
-
55
  iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Eduard's 1st virtual Architect")
56
 
57
  if __name__ == "__main__":
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
2
  import torch
3
  import gradio as gr
4
 
5
  model_id = "eduard76/Llama3-8b-good-new"
6
 
 
 
 
 
 
 
 
7
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
8
+
9
  model = AutoModelForCausalLM.from_pretrained(
10
  model_id,
11
+ device_map="auto", # poate fi "cuda:0" sau "cpu" dacă ai eroare
12
+ torch_dtype=torch.float16, # sau .bfloat16 dacă vrei
 
13
  trust_remote_code=True
14
  )
15
 
16
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
17
 
 
18
  covered_topics = {
19
  "ospf", "bgp", "eigrp", "vxlan", "evpn", "network design", "acl", "routing",
20
  "spine", "leaf", "underlay", "overlay", "mpls", "qos", "firewall",
 
24
  def chat(user_input):
25
  prompt = f"""You are a Cisco-certified network architect trained in OSPF, BGP, EIGRP, VLAN, STP, RSTP design principles.
26
  If the user's question is unclear, clarify first.
27
+ If the topic is outside OSPF, BGP, EIGRP, VLAN, STP, RSTP, respond with: "I'm not trained on that topic."
28
  Give short, clear, non-repetitive answers.
29
 
30
  User: {user_input}
 
43
 
44
  return response[len(prompt):].strip()
45
 
 
46
  iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Eduard's 1st virtual Architect")
47
 
48
  if __name__ == "__main__":