goblingeorge commited on
Commit
093bfef
·
1 Parent(s): 3d0be4f

add application

Browse files
Files changed (3) hide show
  1. README.md +2 -0
  2. app.py +97 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -8,6 +8,8 @@ sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
  short_description: Llama-3.1-TAIDE-LX-8B-Chat demo
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  app_file: app.py
9
  pinned: false
10
  short_description: Llama-3.1-TAIDE-LX-8B-Chat demo
11
+ models:
12
+ - taide/Llama-3.1-TAIDE-LX-8B-Chat
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import litellm
4
+
5
+ DESCRIPTION = '''
6
+ <div>
7
+ <h1 style="text-align: center;">TAIDE/Llama-3.1-TAIDE-LX-8B-Chat</h1>
8
+ <p>This Space demonstrates the instruction-tuned model <a href="https://huggingface.co/taide/Llama-3.1-TAIDE-LX-8B-Chat"><b>Llama-3.1-TAIDE-LX-8B-Chat</b></a>. Llama-3.1-TAIDE-LX-8B-Chat is the new open LLM and comes in one sizes: 8b. Feel free to play with it, or duplicate to run privately!</p>
9
+ </div>
10
+ '''
11
+
12
+ LICENSE = """
13
+ <p/>
14
+ ---
15
+ Built with Llama-3.1-TAIDE-LX-8B-Chat
16
+ """
17
+
18
+ css = """
19
+ h1 {
20
+ text-align: center;
21
+ display: block;
22
+ }
23
+ #duplicate-button {
24
+ margin: auto;
25
+ color: white;
26
+ background: #1565c0;
27
+ border-radius: 100vh;
28
+ }
29
+ """
30
+
31
+
32
+ def chat(message: str,
33
+ history: list,
34
+ temperature: float,
35
+ max_new_tokens: int
36
+ ) -> str:
37
+ try:
38
+ messages = []
39
+ for user, assistant in history:
40
+ messages.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
41
+ messages.append({"role": "user", "content": message})
42
+
43
+ response = litellm.completion(
44
+ model="openai/Llama-3.1-TAIDE-LX-8B-Chat", # tells litellm to call the model via the Responses API
45
+ messages=messages,
46
+ max_completion_tokens=max_new_tokens,
47
+ temperature=temperature,
48
+ stream=True,
49
+
50
+ )
51
+ output = []
52
+ for part in response:
53
+ content = part.choices[0].delta.content or ""
54
+ output.append(content)
55
+ yield "".join(output)
56
+ except Exception as e:
57
+ yield f"生成過程中發生錯誤: {str(e)}"
58
+
59
+
60
+ # Gradio block
61
+ chatbot = gr.Chatbot(height=450, label='Gradio ChatInterface')
62
+
63
+ with gr.Blocks(fill_height=True, css=css) as demo:
64
+
65
+ gr.Markdown(DESCRIPTION)
66
+ gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
67
+ gr.ChatInterface(
68
+ fn=chat,
69
+ chatbot=chatbot,
70
+ fill_height=True,
71
+ additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
72
+ additional_inputs=[
73
+ gr.Slider(minimum=0,
74
+ maximum=1,
75
+ step=0.1,
76
+ value=0.95,
77
+ label="Temperature",
78
+ render=False),
79
+ gr.Slider(minimum=128,
80
+ maximum=131584,
81
+ step=1,
82
+ value=512,
83
+ label="Max new tokens",
84
+ render=False),
85
+ ],
86
+ examples=[
87
+ ['請以以下內容為基礎,寫一篇文章:撰寫一篇作文,題目為《一張舊照片》,內容要求為:選擇一張令你印象深刻的照片,說明令你印象深刻的原因,並描述照片中的影像及背後的故事。記錄成長的過程、與他人的情景、環境變遷和美麗的景色。'],
88
+ ['請以品牌經理的身份,給廣告公司的創意總監寫一封信,提出對於新產品廣告宣傳活動的創意建議。'],
89
+ ['以下提供英文內容,請幫我翻譯成中文。Dongshan coffee is famous for its unique position, and the constant refinement of production methods. The flavor is admired by many caffeine afficionados.'],
90
+ ],
91
+ cache_examples=False,
92
+ )
93
+
94
+ gr.Markdown(LICENSE)
95
+
96
+ if __name__ == "__main__":
97
+ demo.launch(server_name='0.0.0.0')
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ spaces
2
+ gradio
3
+ litellm