Georg4000 commited on
Commit
c6f760b
ยท
verified ยท
1 Parent(s): 1be66b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -13,17 +13,19 @@ if hf_token:
13
  else:
14
  raise ValueError("Hugging Face token is missing. Please check your secrets.")
15
 
16
- # ุงุฎุชูŠุงุฑ ุงู„ู†ู…ูˆุฐุฌ ุงู„ุฃุตุบุฑ
17
- model_name = "Qwen/Qwen1.5-4B-Chat" # ูŠู…ูƒู†ูƒ ุงุณุชุฎุฏุงู… "google/gemma-2b" ุฅุฐุง ุฃุฑุฏุช
18
 
19
  # ุชุญุฏูŠุฏ ุงู„ุฌู‡ุงุฒ ุงู„ู…ู†ุงุณุจ (GPU ุฃูˆ CPU)
20
  device = "cuda" if torch.cuda.is_available() else "cpu"
21
 
22
- # ุชุญู…ูŠู„ ุงู„ู†ู…ูˆุฐุฌ ูˆุงู„ู…ุญูˆู„ ู…ุน ุชู‚ู„ูŠู„ ุงู„ุงุณุชู‡ู„ุงูƒ
23
  model = AutoModelForCausalLM.from_pretrained(
24
  model_name,
25
- torch_dtype=torch.float16,
26
- device_map="auto"
 
 
27
  )
28
  tokenizer = AutoTokenizer.from_pretrained(model_name)
29
 
@@ -44,16 +46,20 @@ custom_responses = {
44
  def chatbot(user_input):
45
  user_input = user_input.lower()
46
 
 
47
  for question, answer in custom_responses.items():
48
  if question in user_input:
49
  return answer
50
 
 
51
  inputs = tokenizer(user_input, return_tensors="pt").to(device)
52
- output = model.generate(**inputs, max_length=100)
53
- response = tokenizer.decode(output[0], skip_special_tokens=True)
54
 
 
 
 
 
55
  return response
56
 
57
- # ุชุดุบูŠู„ ุงู„ูˆุงุฌู‡ุฉ
58
  iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
59
- iface.launch()
 
13
  else:
14
  raise ValueError("Hugging Face token is missing. Please check your secrets.")
15
 
16
+ # ุงุณุชุฎุฏุงู… ู†ู…ูˆุฐุฌ TinyLlama ุงู„ุฃุฎู
17
+ model_name = "TinyLlama/TinyLlama-1.1B-Chat"
18
 
19
  # ุชุญุฏูŠุฏ ุงู„ุฌู‡ุงุฒ ุงู„ู…ู†ุงุณุจ (GPU ุฃูˆ CPU)
20
  device = "cuda" if torch.cuda.is_available() else "cpu"
21
 
22
+ # ุชุญู…ูŠู„ ุงู„ู†ู…ูˆุฐุฌ ูˆุงู„ู…ุญูˆู„
23
  model = AutoModelForCausalLM.from_pretrained(
24
  model_name,
25
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
26
+ device_map="auto",
27
+ token=hf_token,
28
+ trust_remote_code=True
29
  )
30
  tokenizer = AutoTokenizer.from_pretrained(model_name)
31
 
 
46
  def chatbot(user_input):
47
  user_input = user_input.lower()
48
 
49
+ # ุงู„ุชุญู‚ู‚ ู…ู† ุงู„ุฑุฏูˆุฏ ุงู„ู…ุฎุตุตุฉ ุฃูˆู„ุงู‹
50
  for question, answer in custom_responses.items():
51
  if question in user_input:
52
  return answer
53
 
54
+ # ู…ุนุงู„ุฌุฉ ุงู„ุฅุฏุฎุงู„ ุจุงุณุชุฎุฏุงู… ุงู„ู†ู…ูˆุฐุฌ
55
  inputs = tokenizer(user_input, return_tensors="pt").to(device)
 
 
56
 
57
+ with torch.no_grad(): # ุชู‚ู„ูŠู„ ุงุณุชู‡ู„ุงูƒ ุงู„ุฐุงูƒุฑุฉ
58
+ output = model.generate(**inputs, max_length=100)
59
+
60
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
61
  return response
62
 
63
+ # ุชุดุบูŠู„ ุงู„ูˆุงุฌู‡ุฉ ู…ุน Gradio
64
  iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
65
+ iface.launch(share=True)