Nickybymer commited on
Commit
ad13e79
·
verified ·
1 Parent(s): bab38e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -1,26 +1,25 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Tải các mô hình
5
- text_generator = pipeline("text-generation", model="gpt2")
6
- image_classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
- # Hàm xử lý đầu vào
9
- def process_input(text, image=None):
10
- if image is not None:
11
- results = image_classifier(image)
12
- return {result['label']: result['score'] for result in results}
13
- else:
14
- results = text_generator(text, max_length=100, num_return_sequences=1)
15
- return results[0]["generated_text"]
16
 
17
- # Giao diện kết hợp
18
  interface = gr.Interface(
19
- fn=process_input,
20
- inputs=["text", "image"],
21
  outputs="text",
22
- title="Multimodal AI",
23
- description="Nhập văn bản hoặc tải ảnh để AI xử lý."
24
  )
25
 
26
  interface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
+ # Tải mô hình và tokenizer cho tiếng Việt
5
+ tokenizer = AutoTokenizer.from_pretrained("vinai/phobert-base")
6
+ model = AutoModelForCausalLM.from_pretrained("vinai/phobert-base")
7
 
8
+ # Hàm xử lý hội thoại
9
+ def chatbot_response(input_text):
10
+ # Token hóa văn bản
11
+ inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
12
+ outputs = model.generate(inputs["input_ids"], max_length=50, num_return_sequences=1)
13
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+ return response
 
15
 
16
+ # Giao diện Gradio
17
  interface = gr.Interface(
18
+ fn=chatbot_response,
19
+ inputs="text",
20
  outputs="text",
21
+ title="Chatbot Tiếng Việt",
22
+ description="Nhập câu hỏi hoặc tin nhắn để AI phản hồi bằng tiếng Việt."
23
  )
24
 
25
  interface.launch()