Update app.py
Browse files
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 = "
|
| 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)
|