phucdt89s commited on
Commit
09f84eb
·
verified ·
1 Parent(s): 5705dc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -1,17 +1,20 @@
1
- from llama_cpp import Llama
2
  import gradio as gr
3
 
4
- # Load model
5
- MODEL_PATH = "./model/vinallama-2.7b-chat.gguf" # Đường dẫn đến mô hình GGUF
6
- model = Llama(model_path=MODEL_PATH)
7
 
8
- # Define chatbot function
9
- def chatbot(input_text):
10
- response = model(input_text, max_tokens=200, temperature=0.7)
11
- return response['choices'][0]['text']
12
 
13
- # Create Gradio interface
14
- interface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="Vinamallama 7B Chatbot")
 
 
 
 
15
 
16
- # Launch app
 
17
  interface.launch()
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
  import gradio as gr
3
 
4
+ # Sử dụng tên mô hình từ Hugging Face
5
+ MODEL_NAME = "vilm/vinallama-2.7b-chat-GGUF"
 
6
 
7
+ # Tải hình và tokenizer
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
 
10
 
11
+ # Hàm chatbot
12
+ def chatbot(input_text):
13
+ inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
14
+ outputs = model.generate(inputs["input_ids"], max_length=200, do_sample=True, temperature=0.7)
15
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return response
17
 
18
+ # Giao diện Gradio
19
+ interface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="Vinamallama Chatbot")
20
  interface.launch()