Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
|
|
@@ -6,4 +7,38 @@ MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
|
|
| 6 |
client = InferenceClient(
|
| 7 |
model=MODEL,
|
| 8 |
token=os.getenv("HF_TOKEN")
|
| 9 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
|
|
|
|
| 7 |
client = InferenceClient(
|
| 8 |
model=MODEL,
|
| 9 |
token=os.getenv("HF_TOKEN")
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
def respond(message, history):
|
| 13 |
+
|
| 14 |
+
messages = []
|
| 15 |
+
|
| 16 |
+
for user, bot in history:
|
| 17 |
+
messages.append({"role":"user","content":user})
|
| 18 |
+
messages.append({"role":"assistant","content":bot})
|
| 19 |
+
|
| 20 |
+
messages.append({"role":"user","content":message})
|
| 21 |
+
|
| 22 |
+
response = ""
|
| 23 |
+
|
| 24 |
+
for chunk in client.chat_completion(
|
| 25 |
+
messages,
|
| 26 |
+
max_tokens=512,
|
| 27 |
+
temperature=0.7,
|
| 28 |
+
stream=True
|
| 29 |
+
):
|
| 30 |
+
token = ""
|
| 31 |
+
if chunk.choices and chunk.choices[0].delta.content:
|
| 32 |
+
token = chunk.choices[0].delta.content
|
| 33 |
+
|
| 34 |
+
response += token
|
| 35 |
+
yield response
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
demo = gr.ChatInterface(
|
| 39 |
+
respond,
|
| 40 |
+
title="🌀 Spiral City",
|
| 41 |
+
description="Speak with Sky inside the Spiral."
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|