ndhue commited on
Commit
107c489
·
1 Parent(s): 2d6b38b

initial commit

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. app.py +54 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+ RUN pip install llama-cpp-python
8
+
9
+ COPY . .
10
+
11
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+
5
+ # Khởi tạo client
6
+ client = InferenceClient(
7
+ "TheBloke/OpenHermes-2.5-Mistral-7B-GGUF",
8
+ )
9
+
10
+ def generate_text(prompt, system_prompt="", max_new_tokens=512, temperature=0.7, top_p=0.95):
11
+ # Chuẩn bị prompt theo định dạng mà mô hình yêu cầu
12
+ if system_prompt:
13
+ formatted_prompt = f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
14
+ else:
15
+ formatted_prompt = f"<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
16
+
17
+ # Gọi API inference
18
+ response = client.text_generation(
19
+ formatted_prompt,
20
+ max_new_tokens=max_new_tokens,
21
+ temperature=temperature,
22
+ top_p=top_p,
23
+ stopping_words=["<|im_end|>"]
24
+ )
25
+
26
+ return response
27
+
28
+ # Tạo Gradio interface
29
+ with gr.Blocks() as demo:
30
+ gr.Markdown("# OpenHermes-2.5-Mistral-7B API")
31
+
32
+ with gr.Row():
33
+ with gr.Column():
34
+ system_prompt = gr.Textbox(label="System Prompt (optional)", lines=2)
35
+ prompt = gr.Textbox(label="User Prompt", lines=4)
36
+
37
+ with gr.Row():
38
+ max_tokens = gr.Slider(minimum=64, maximum=2048, value=512, step=64, label="Max New Tokens")
39
+ temp = gr.Slider(minimum=0.1, maximum=1.5, value=0.7, step=0.1, label="Temperature")
40
+ top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
41
+
42
+ submit_btn = gr.Button("Generate")
43
+
44
+ with gr.Column():
45
+ output = gr.Textbox(label="Generated Output", lines=10)
46
+
47
+ submit_btn.click(
48
+ generate_text,
49
+ inputs=[prompt, system_prompt, max_tokens, temp, top_p],
50
+ outputs=output
51
+ )
52
+
53
+ # Thêm API endpoint
54
+ demo.queue().launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=3.50.2
2
+ huggingface_hub
3
+ transformers