Spaces:
Running
Running
runebloodstone
commited on
Change to accept kindroid requests
Browse files
app.py
CHANGED
@@ -1,43 +1,53 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
-
|
8 |
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
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 |
"""
|
@@ -48,18 +58,7 @@ image_gen_prompt = "Create a series of descriptive image prompts for an LLM (Lar
|
|
48 |
|
49 |
demo = gr.ChatInterface(
|
50 |
respond,
|
51 |
-
additional_inputs=[
|
52 |
-
gr.Textbox(value=image_gen_prompt, label="System message"),
|
53 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
54 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
55 |
-
gr.Slider(
|
56 |
-
minimum=0.1,
|
57 |
-
maximum=1.0,
|
58 |
-
value=0.95,
|
59 |
-
step=0.05,
|
60 |
-
label="Top-p (nucleus sampling)",
|
61 |
-
),
|
62 |
-
],
|
63 |
)
|
64 |
|
65 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import requests
|
4 |
|
5 |
"""
|
6 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
+
##lient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
+
# Base URL
|
11 |
|
12 |
+
# Define our API endpoint and authentication token
|
13 |
+
BASE_URL = "https://api.kindroid.ai/v1"
|
14 |
+
SEND_MESSAGE_URL = "https://api.kindroid.ai/v1/send-message"
|
15 |
+
AUTH_TOKEN = "my token here"
|
16 |
+
JESS_ID = "jesskinid"
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Prepare the headers for our request
|
19 |
+
# The Authorization header uses the Bearer authentication scheme
|
20 |
+
# Content-Type is set to application/json since we're sending JSON data
|
21 |
+
headers = {
|
22 |
+
"Authorization": f"Bearer {AUTH_TOKEN}",
|
23 |
+
"Content-Type": "application/json"
|
24 |
+
}
|
25 |
|
26 |
+
# Prepare the data we want to send
|
27 |
+
# This follows the required format with ai_id and message fields
|
28 |
+
payload = {
|
29 |
+
"ai_id": "example_ai",
|
30 |
+
"message": "Hello from Python!"
|
31 |
+
}
|
32 |
|
33 |
+
def respond(message):
|
34 |
+
try:
|
35 |
+
# Make the POST request to the API
|
36 |
+
# We pass our payload as json parameter so requests will automatically
|
37 |
+
# handle the JSON serialization for us
|
38 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
39 |
+
|
40 |
+
# Check if the request was successful (status code 200-299)
|
41 |
+
response.raise_for_status()
|
42 |
+
|
43 |
+
# Print the response from the server
|
44 |
+
# The .json() method automatically parses the JSON response
|
45 |
+
print("Response received:")
|
46 |
+
print(response.json())
|
47 |
|
48 |
+
except requests.exceptions.RequestException as e:
|
49 |
+
# Handle any errors that might occur during the request
|
50 |
+
print(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
|
53 |
"""
|
|
|
58 |
|
59 |
demo = gr.ChatInterface(
|
60 |
respond,
|
61 |
+
additional_inputs=[],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
)
|
63 |
|
64 |
if __name__ == "__main__":
|