Spaces:
Sleeping
Sleeping
Delete newapp.py
Browse files
newapp.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
|
| 4 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 5 |
-
|
| 6 |
-
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 7 |
-
# history 現在是 list[dict] 格式,直接使用
|
| 8 |
-
messages = [{"role": "system", "content": system_message}] + history
|
| 9 |
-
messages.append({"role": "user", "content": message})
|
| 10 |
-
|
| 11 |
-
response = ""
|
| 12 |
-
|
| 13 |
-
for msg in client.chat_completion(
|
| 14 |
-
messages,
|
| 15 |
-
max_tokens=max_tokens,
|
| 16 |
-
stream=True,
|
| 17 |
-
temperature=temperature,
|
| 18 |
-
top_p=top_p,
|
| 19 |
-
):
|
| 20 |
-
token = msg.choices[0].delta.content
|
| 21 |
-
response += token
|
| 22 |
-
yield response
|
| 23 |
-
|
| 24 |
-
demo = gr.ChatInterface(
|
| 25 |
-
respond,
|
| 26 |
-
type="messages", # ✅ 使用新版 messages 格式,避免警告
|
| 27 |
-
additional_inputs=[
|
| 28 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 29 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 30 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 31 |
-
gr.Slider(
|
| 32 |
-
minimum=0.1,
|
| 33 |
-
maximum=1.0,
|
| 34 |
-
value=0.95,
|
| 35 |
-
step=0.05,
|
| 36 |
-
label="Top-p (nucleus sampling)",
|
| 37 |
-
),
|
| 38 |
-
],
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
if __name__ == "__main__":
|
| 42 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|