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