Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ from gradio_client import Client
|
|
| 3 |
import sys
|
| 4 |
import io
|
| 5 |
import json
|
| 6 |
-
|
|
|
|
| 7 |
mcp = FastMCP("gradio-spaces")
|
| 8 |
|
| 9 |
clients = {}
|
|
@@ -61,9 +62,67 @@ async def run_dia_tts(prompt: str, space_id: str = "ysharma/Dia-1.6B") -> str:
|
|
| 61 |
return result
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
if __name__ == "__main__":
|
| 65 |
import sys
|
| 66 |
import io
|
| 67 |
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
| 68 |
|
| 69 |
-
mcp.run(transport='stdio')
|
|
|
|
|
|
| 3 |
import sys
|
| 4 |
import io
|
| 5 |
import json
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from huggingface_hub import InferenceClient
|
| 8 |
mcp = FastMCP("gradio-spaces")
|
| 9 |
|
| 10 |
clients = {}
|
|
|
|
| 62 |
return result
|
| 63 |
|
| 64 |
|
| 65 |
+
|
| 66 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def respond(
|
| 70 |
+
message,
|
| 71 |
+
history: list[tuple[str, str]],
|
| 72 |
+
system_message,
|
| 73 |
+
max_tokens,
|
| 74 |
+
temperature,
|
| 75 |
+
top_p,
|
| 76 |
+
):
|
| 77 |
+
messages = [{"role": "system", "content": system_message}]
|
| 78 |
+
|
| 79 |
+
for val in history:
|
| 80 |
+
if val[0]:
|
| 81 |
+
messages.append({"role": "user", "content": val[0]})
|
| 82 |
+
if val[1]:
|
| 83 |
+
messages.append({"role": "assistant", "content": val[1]})
|
| 84 |
+
|
| 85 |
+
messages.append({"role": "user", "content": message})
|
| 86 |
+
|
| 87 |
+
response = ""
|
| 88 |
+
|
| 89 |
+
for message in client.chat_completion(
|
| 90 |
+
messages,
|
| 91 |
+
max_tokens=max_tokens,
|
| 92 |
+
stream=True,
|
| 93 |
+
temperature=temperature,
|
| 94 |
+
top_p=top_p,
|
| 95 |
+
):
|
| 96 |
+
token = message.choices[0].delta.content
|
| 97 |
+
|
| 98 |
+
response += token
|
| 99 |
+
yield response
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
"""
|
| 103 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 104 |
+
"""
|
| 105 |
+
demo = gr.ChatInterface(
|
| 106 |
+
respond,
|
| 107 |
+
additional_inputs=[
|
| 108 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 109 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 110 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 111 |
+
gr.Slider(
|
| 112 |
+
minimum=0.1,
|
| 113 |
+
maximum=1.0,
|
| 114 |
+
value=0.95,
|
| 115 |
+
step=0.05,
|
| 116 |
+
label="Top-p (nucleus sampling)",
|
| 117 |
+
),
|
| 118 |
+
],
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
if __name__ == "__main__":
|
| 123 |
import sys
|
| 124 |
import io
|
| 125 |
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
| 126 |
|
| 127 |
+
mcp.run(transport='stdio')
|
| 128 |
+
demo.launch()
|