Spaces:
Runtime error
Runtime error
app.py
CHANGED
|
@@ -1,53 +1,49 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 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
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 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(
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
gr.Slider(
|
| 52 |
minimum=0.1,
|
| 53 |
maximum=1.0,
|
|
@@ -58,6 +54,5 @@ demo = gr.ChatInterface(
|
|
| 58 |
],
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
if __name__ == "__main__":
|
| 63 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Set up the API endpoint and key
|
| 6 |
+
API_URL = "https://api.runpod.ai/v2/vllm-2lzb7pk51fq0wd/openai/v1/chat/completions"
|
| 7 |
+
API_KEY = os.getenv("RUNPOD_API_KEY") # Make sure to set this in your Hugging Face Space secrets
|
|
|
|
| 8 |
|
| 9 |
+
headers = {
|
| 10 |
+
"Authorization": f"Bearer {API_KEY}",
|
| 11 |
+
"Content-Type": "application/json"
|
| 12 |
+
}
|
| 13 |
|
| 14 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
messages = [{"role": "system", "content": system_message}]
|
| 16 |
+
|
| 17 |
+
for human, assistant in history:
|
| 18 |
+
messages.append({"role": "user", "content": human})
|
| 19 |
+
messages.append({"role": "assistant", "content": assistant})
|
| 20 |
+
|
|
|
|
|
|
|
| 21 |
messages.append({"role": "user", "content": message})
|
| 22 |
+
|
| 23 |
+
data = {
|
| 24 |
+
"model": "forcemultiplier/fmx-reflective-2b", # Adjust if needed
|
| 25 |
+
"messages": messages,
|
| 26 |
+
"max_tokens": max_tokens,
|
| 27 |
+
"temperature": temperature,
|
| 28 |
+
"top_p": top_p
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
| 32 |
+
|
| 33 |
+
if response.status_code == 200:
|
| 34 |
+
return response.json()['choices'][0]['message']['content']
|
| 35 |
+
else:
|
| 36 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
demo = gr.ChatInterface(
|
| 39 |
respond,
|
| 40 |
additional_inputs=[
|
| 41 |
+
gr.Textbox(
|
| 42 |
+
value="You are an advanced artificial intelligence system, capable of <thinking> <reflection> and you output a brief and to-the-point <output>.",
|
| 43 |
+
label="System message"
|
| 44 |
+
),
|
| 45 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max tokens"),
|
| 46 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
|
| 47 |
gr.Slider(
|
| 48 |
minimum=0.1,
|
| 49 |
maximum=1.0,
|
|
|
|
| 54 |
],
|
| 55 |
)
|
| 56 |
|
|
|
|
| 57 |
if __name__ == "__main__":
|
| 58 |
demo.launch()
|