tolgadev commited on
Commit
b532d19
1 Parent(s): e265cdb

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +6 -9
  2. app.py +62 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,10 @@
1
  ---
2
- title: Chat With TrendyolLLM
3
- emoji: 😻
4
  colorFrom: red
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 4.18.0
8
  app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: TrendyolLLM-Chat
3
+ emoji: 🛒
4
  colorFrom: red
5
+ colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 4.7.1
8
  app_file: app.py
9
+ pinned: true
10
+ ---
 
 
 
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from pathlib import Path
4
+ import argparse
5
+ from huggingface_hub import snapshot_download
6
+ from llama_cpp import Llama
7
+
8
+ repo_name = 'tolgadev/Trendyol-LLM-7b-chat-v0.1-GGUF'
9
+ model_file = "trendyol-llm-7b-chat-v0.1.Q5_K_M.gguf"
10
+
11
+ snapshot_download(repo_id=repo_name, local_dir=".", allow_patterns=model_file)
12
+
13
+ DEFAULT_MODEL_PATH = model_file
14
+ llm = Llama(model_path=model_file, model_type="llama")
15
+
16
+ def predict(input, chatbot, max_length, top_p, temperature, history):
17
+ chatbot.append((input, ""))
18
+ response = ""
19
+ history.append(input)
20
+
21
+ for output in llm(input, stream=True, temperature=temperature, top_p=top_p, max_tokens=max_length, ):
22
+ piece = output['choices'][0]['text']
23
+ response += piece
24
+ chatbot[-1] = (chatbot[-1][0], response)
25
+
26
+ yield chatbot, history
27
+
28
+ history.append(response)
29
+ yield chatbot, history
30
+
31
+
32
+ def reset_user_input():
33
+ return gr.update(value="")
34
+
35
+ def reset_state():
36
+ return [], []
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.HTML("""<h1 align="center">TrendyolLLM Chatbot Demo</h1>
40
+ <h3 align="center">This is unofficial demo of [```tolgadev/Trendyol-LLM-7b-chat-v0.1-GGUF```](https://huggingface.co/tolgadev/Trendyol-LLM-7b-chat-v0.1-GGUF) model based on ```LLama2 architecture```.</h3>""")
41
+
42
+ chatbot = gr.Chatbot()
43
+ with gr.Row():
44
+ with gr.Column(scale=4):
45
+ user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=8, elem_id="user_input")
46
+ submitBtn = gr.Button("Submit", variant="primary", elem_id="submit_btn")
47
+ with gr.Column(scale=1):
48
+ max_length = gr.Slider(0, 256, value=64, step=1.0, label="Maximum Length", interactive=True)
49
+ top_p = gr.Slider(0, 1, value=0.7, step=0.01, label="Top P", interactive=True)
50
+ temperature = gr.Slider(0, 2.0, value=0.95, step=0.01, label="Temperature", interactive=True)
51
+ emptyBtn = gr.Button("Clear History")
52
+
53
+ history = gr.State([])
54
+
55
+ submitBtn.click(
56
+ predict, [user_input, chatbot, max_length, top_p, temperature, history], [chatbot, history], show_progress=True
57
+ )
58
+ submitBtn.click(reset_user_input, [], [user_input])
59
+
60
+ emptyBtn.click(reset_state, outputs=[chatbot, history], show_progress=True)
61
+
62
+ demo.queue().launch(share=False, inbrowser=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ llama-cpp-python==0.2.11
2
+ huggingface-hub==0.14.1
3
+ gradio==3.32.0