youzarsiph commited on
Commit
862772f
1 Parent(s): d4fc1f3

initial setup

Browse files
Files changed (3) hide show
  1. .gitignore +132 -0
  2. app.py +57 -28
  3. requirements.txt +1 -1
.gitignore ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Static files css / js
2
+ node_modules/
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ pip-wheel-metadata/
27
+ share/python-wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # PyInstaller
34
+ # Usually these files are written by a python script from a template
35
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *.cover
53
+ *.py,cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
98
+ __pypackages__/
99
+
100
+ # Celery stuff
101
+ celerybeat-schedule
102
+ celerybeat.pid
103
+
104
+ # SageMath parsed files
105
+ *.sage.py
106
+
107
+ # Environments
108
+ .env
109
+ .venv
110
+ env/
111
+ venv/
112
+ ENV/
113
+ env.bak/
114
+ venv.bak/
115
+
116
+ # Spyder project settings
117
+ .spyderproject
118
+ .spyproject
119
+
120
+ # Rope project settings
121
+ .ropeproject
122
+
123
+ # mkdocs documentation
124
+ /site
125
+
126
+ # mypy
127
+ .mypy_cache/
128
+ .dmypy.json
129
+ dmypy.json
130
+
131
+ # Pyre type checker
132
+ .pyre/
app.py CHANGED
@@ -1,63 +1,92 @@
 
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
 
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
  ):
 
 
 
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
  for val in history:
21
  if val[0]:
22
  messages.append({"role": "user", "content": val[0]})
 
23
  if val[1]:
24
  messages.append({"role": "assistant", "content": val[1]})
25
 
 
26
  messages.append({"role": "user", "content": message})
27
 
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
33
- stream=True,
34
  temperature=temperature,
35
  top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
 
 
 
 
 
 
 
 
 
38
 
39
- response += token
40
- yield response
41
 
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
  demo = gr.ChatInterface(
46
- respond,
 
 
 
 
 
47
  additional_inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  gr.Slider(
52
  minimum=0.1,
53
  maximum=1.0,
54
  value=0.95,
55
  step=0.05,
56
- label="Top-p (nucleus sampling)",
57
  ),
58
  ],
59
  )
60
 
61
 
62
  if __name__ == "__main__":
63
- demo.launch()
 
1
+ """ Star Coder2 chat demo """
2
+
3
+ from typing import List, Tuple, Union
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
6
 
7
+
8
+ # HF InferenceClient
9
+ client = InferenceClient("microsoft/Phi-3.5-mini-instruct")
 
10
 
11
 
12
+ def chat(
13
+ message: str,
14
+ history: List[Tuple[str, str]],
15
+ system_message: str,
16
+ max_tokens: Union[int, None],
17
+ temperature: Union[float, None],
18
+ top_p: Union[float, None],
19
  ):
20
+ """Code assistant"""
21
+
22
+ # Chat history
23
  messages = [{"role": "system", "content": system_message}]
24
 
25
  for val in history:
26
  if val[0]:
27
  messages.append({"role": "user", "content": val[0]})
28
+
29
  if val[1]:
30
  messages.append({"role": "assistant", "content": val[1]})
31
 
32
+ # Add user message
33
  messages.append({"role": "user", "content": message})
34
 
35
+ llm_message = client.chat_completion(
 
 
36
  messages,
37
  max_tokens=max_tokens,
 
38
  temperature=temperature,
39
  top_p=top_p,
40
+ )
41
+
42
+ # Add chatbot message
43
+ messages.append(
44
+ {
45
+ "role": "assistant",
46
+ "content": llm_message.choices[0].message.content,
47
+ }
48
+ )
49
+
50
+ yield llm_message.choices[0].message.content
51
 
 
 
52
 
53
+ # UI
 
 
54
  demo = gr.ChatInterface(
55
+ chat,
56
+ title="Phi-3.5-mini-instruct",
57
+ theme="soft",
58
+ description="Phi-3.5-mini is a lightweight, state-of-the-art open model built upon "
59
+ "datasets used for Phi-3 - synthetic data and filtered publicly available websites - "
60
+ "with a focus on very high-quality, reasoning dense data.",
61
  additional_inputs=[
62
+ gr.Textbox(
63
+ value="You are a friendly chatbot.",
64
+ label="System message",
65
+ ),
66
+ gr.Slider(
67
+ minimum=1,
68
+ maximum=2048,
69
+ value=512,
70
+ step=1,
71
+ label="Max new tokens",
72
+ ),
73
+ gr.Slider(
74
+ minimum=0.1,
75
+ maximum=4.0,
76
+ value=0.7,
77
+ step=0.1,
78
+ label="Temperature",
79
+ ),
80
  gr.Slider(
81
  minimum=0.1,
82
  maximum=1.0,
83
  value=0.95,
84
  step=0.05,
85
+ label="Top-p",
86
  ),
87
  ],
88
  )
89
 
90
 
91
  if __name__ == "__main__":
92
+ demo.launch()
requirements.txt CHANGED
@@ -1 +1 @@
1
- huggingface_hub==0.22.2
 
1
+ huggingface_hub==0.25.1