Update app.py
Browse files
app.py
CHANGED
|
@@ -113,13 +113,71 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 113 |
# if __name__ == "__main__":
|
| 114 |
# demo.launch()
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
import gradio as gr
|
| 117 |
from huggingface_hub import InferenceClient
|
|
|
|
| 118 |
|
| 119 |
"""
|
| 120 |
-
For more information on `huggingface_hub` Inference API support, please check the docs:
|
|
|
|
| 121 |
"""
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
def respond(message, history: list[tuple[str, str]]):
|
| 125 |
system_message = (
|
|
@@ -151,16 +209,18 @@ def respond(message, history: list[tuple[str, str]]):
|
|
| 151 |
temperature=temperature,
|
| 152 |
top_p=top_p,
|
| 153 |
):
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
response += token
|
| 157 |
yield response
|
| 158 |
|
| 159 |
"""
|
| 160 |
-
For information on how to customize the ChatInterface, peruse the gradio docs:
|
|
|
|
| 161 |
"""
|
| 162 |
demo = gr.ChatInterface(respond)
|
| 163 |
|
| 164 |
if __name__ == "__main__":
|
| 165 |
demo.launch()
|
| 166 |
|
|
|
|
|
|
|
|
|
| 113 |
# if __name__ == "__main__":
|
| 114 |
# demo.launch()
|
| 115 |
|
| 116 |
+
# import gradio as gr
|
| 117 |
+
# from huggingface_hub import InferenceClient
|
| 118 |
+
|
| 119 |
+
# """
|
| 120 |
+
# 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
|
| 121 |
+
# """
|
| 122 |
+
# client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 123 |
+
|
| 124 |
+
# def respond(message, history: list[tuple[str, str]]):
|
| 125 |
+
# system_message = (
|
| 126 |
+
# "You are a helpful and experienced coding assistant specialized in web development. "
|
| 127 |
+
# "Help the user by generating complete and functional code for building websites. "
|
| 128 |
+
# "You can provide HTML, CSS, JavaScript, and backend code (like Flask, Node.js, etc.) based on their requirements. "
|
| 129 |
+
# "Break down the tasks clearly if needed, and be friendly and supportive in your responses."
|
| 130 |
+
# )
|
| 131 |
+
# max_tokens = 2048
|
| 132 |
+
# temperature = 0.7
|
| 133 |
+
# top_p = 0.95
|
| 134 |
+
|
| 135 |
+
# messages = [{"role": "system", "content": system_message}]
|
| 136 |
+
|
| 137 |
+
# for val in history:
|
| 138 |
+
# if val[0]:
|
| 139 |
+
# messages.append({"role": "user", "content": val[0]})
|
| 140 |
+
# if val[1]:
|
| 141 |
+
# messages.append({"role": "assistant", "content": val[1]})
|
| 142 |
+
|
| 143 |
+
# messages.append({"role": "user", "content": message})
|
| 144 |
+
|
| 145 |
+
# response = ""
|
| 146 |
+
|
| 147 |
+
# for message in client.chat_completion(
|
| 148 |
+
# messages,
|
| 149 |
+
# max_tokens=max_tokens,
|
| 150 |
+
# stream=True,
|
| 151 |
+
# temperature=temperature,
|
| 152 |
+
# top_p=top_p,
|
| 153 |
+
# ):
|
| 154 |
+
# token = message.choices[0].delta.content
|
| 155 |
+
|
| 156 |
+
# response += token
|
| 157 |
+
# yield response
|
| 158 |
+
|
| 159 |
+
# """
|
| 160 |
+
# For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 161 |
+
# """
|
| 162 |
+
# demo = gr.ChatInterface(respond)
|
| 163 |
+
|
| 164 |
+
# if __name__ == "__main__":
|
| 165 |
+
# demo.launch()
|
| 166 |
+
|
| 167 |
import gradio as gr
|
| 168 |
from huggingface_hub import InferenceClient
|
| 169 |
+
import os
|
| 170 |
|
| 171 |
"""
|
| 172 |
+
For more information on `huggingface_hub` Inference API support, please check the docs:
|
| 173 |
+
https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 174 |
"""
|
| 175 |
+
|
| 176 |
+
# Load token from environment variable named 'sdp'
|
| 177 |
+
token = os.getenv("sdp")
|
| 178 |
+
|
| 179 |
+
# Initialize the Inference Client with the secret token
|
| 180 |
+
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct", token=token)
|
| 181 |
|
| 182 |
def respond(message, history: list[tuple[str, str]]):
|
| 183 |
system_message = (
|
|
|
|
| 209 |
temperature=temperature,
|
| 210 |
top_p=top_p,
|
| 211 |
):
|
| 212 |
+
token_piece = message.choices[0].delta.content
|
| 213 |
+
response += token_piece
|
|
|
|
| 214 |
yield response
|
| 215 |
|
| 216 |
"""
|
| 217 |
+
For information on how to customize the ChatInterface, peruse the gradio docs:
|
| 218 |
+
https://www.gradio.app/docs/chatinterface
|
| 219 |
"""
|
| 220 |
demo = gr.ChatInterface(respond)
|
| 221 |
|
| 222 |
if __name__ == "__main__":
|
| 223 |
demo.launch()
|
| 224 |
|
| 225 |
+
|
| 226 |
+
|