Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import torch
|
|
|
|
| 3 |
from huggingface_hub import login
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
import gradio as gr
|
|
@@ -26,8 +27,7 @@ def build_prompt(history, new_message):
|
|
| 26 |
prompt += f"User: {new_message}\nAI:"
|
| 27 |
return prompt
|
| 28 |
|
| 29 |
-
def chat(history, new_message):
|
| 30 |
-
# Đảm bảo history là list (khi nhập trực tiếp trên UI đôi khi là str)
|
| 31 |
if isinstance(history, str):
|
| 32 |
import ast
|
| 33 |
try:
|
|
@@ -63,7 +63,6 @@ with gr.Blocks() as demo:
|
|
| 63 |
btn = gr.Button("Gửi")
|
| 64 |
btn.click(_chat_ui, inputs=[history, new_message], outputs=output)
|
| 65 |
|
| 66 |
-
# Định nghĩa API endpoint /api/chat_ai
|
| 67 |
gr.api(chat, api_name="chat_ai")
|
| 68 |
|
| 69 |
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import torch
|
| 3 |
+
from typing import List, Union
|
| 4 |
from huggingface_hub import login
|
| 5 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 6 |
import gradio as gr
|
|
|
|
| 27 |
prompt += f"User: {new_message}\nAI:"
|
| 28 |
return prompt
|
| 29 |
|
| 30 |
+
def chat(history: Union[str, List[str]], new_message: str) -> str:
|
|
|
|
| 31 |
if isinstance(history, str):
|
| 32 |
import ast
|
| 33 |
try:
|
|
|
|
| 63 |
btn = gr.Button("Gửi")
|
| 64 |
btn.click(_chat_ui, inputs=[history, new_message], outputs=output)
|
| 65 |
|
|
|
|
| 66 |
gr.api(chat, api_name="chat_ai")
|
| 67 |
|
| 68 |
demo.launch()
|