NeuralInternet Defalt-404 commited on
Commit
834b82c
0 Parent(s):

Duplicate from Defalt-404/Top-VS-Benchmark_Bittensor

Browse files

Co-authored-by: Kunj Kansara <Defalt-404@users.noreply.huggingface.co>

Files changed (3) hide show
  1. .gitattributes +35 -0
  2. README.md +13 -0
  3. app.py +104 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Top-VS-Benchmark Bittensor
3
+ emoji: 🏢
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 3.43.2
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: Defalt-404/Top-VS-Benchmark_Bittensor
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import ssl
4
+ import http.client
5
+
6
+ def get_api_key():
7
+
8
+ context = ssl.create_default_context()
9
+ context.check_hostname = True
10
+
11
+ conn = http.client.HTTPSConnection("test.neuralinternet.ai", context=context)
12
+ conn.request("GET", "/admin/api-keys/")
13
+ api_key_resp = conn.getresponse()
14
+ api_key_string = api_key_resp.read().decode("utf-8").replace("\n", "").replace("\t", "")
15
+ api_key_json = json.loads(api_key_string)
16
+ api_key = api_key_json[0]['api_key']
17
+ conn.close()
18
+ return api_key
19
+
20
+ def generate_top_response(system_prompt,model_input, api_key):
21
+ payload = json.dumps(
22
+ {"top_n": 100, "messages": [{"role": "system", "content": system_prompt},{"role": "user", "content": model_input}]}
23
+ )
24
+
25
+ headers = {
26
+ "Content-Type": "application/json",
27
+ "Authorization": f"Bearer {api_key}",
28
+ "Endpoint-Version": "2023-05-19",
29
+ }
30
+
31
+ context = ssl.create_default_context()
32
+ context.check_hostname = True
33
+
34
+ conn = http.client.HTTPSConnection("test.neuralinternet.ai", context=context)
35
+ conn.request("POST", "/chat", payload, headers)
36
+ response = conn.getresponse()
37
+ utf_string = response.read().decode("utf-8").replace("\n", "").replace("\t", "")
38
+ print(utf_string)
39
+ json_resp = json.loads(utf_string)
40
+ conn.close()
41
+ for choice in json_resp['choices']:
42
+ uid = choice['uid']
43
+ return uid, choice['message']['content']
44
+
45
+ def generate_benchmark_response(system_prompt, model_input, api_key):
46
+
47
+ context = ssl.create_default_context()
48
+ context.check_hostname = True
49
+
50
+
51
+ conn = http.client.HTTPSConnection("test.neuralinternet.ai", context=context)
52
+ conn.request("GET", "/top_miner_uids")
53
+ benchmark_uid_resp = conn.getresponse()
54
+ benchmark_uid_string = benchmark_uid_resp.read().decode("utf-8").replace("\n", "").replace("\t", "")
55
+ benchmark_uid_json = json.loads(benchmark_uid_string)
56
+ conn.close()
57
+
58
+ payload = json.dumps(
59
+ {"uids": benchmark_uid_json , "messages": [{"role": "system", "content": system_prompt},{"role": "user", "content": model_input}]}
60
+ )
61
+
62
+ headers = {
63
+ "Content-Type": "application/json",
64
+ "Authorization": f"Bearer {api_key}",
65
+ "Endpoint-Version": "2023-05-19",
66
+ }
67
+
68
+ conn = http.client.HTTPSConnection("test.neuralinternet.ai", context=context)
69
+ conn.request("POST", "/chat", payload, headers)
70
+ response = conn.getresponse()
71
+ utf_string = response.read().decode("utf-8").replace("\n", "").replace("\t", "")
72
+ json_resp = json.loads(utf_string)
73
+ #print(utf_string)
74
+ conn.close()
75
+
76
+ for choice in json_resp['choices']:
77
+ uid = choice['uid']
78
+ model_resp = choice['message']['content']
79
+ return uid, model_resp
80
+
81
+ def dynamic_function(system_prompt, prompt):
82
+
83
+ if len(system_prompt) == 0:
84
+ system_prompt = "You are an AI Assistant, created by bittensor and powered by NI(Neural Internet). Your task is to provide consise response to user's prompt"
85
+ api_key = get_api_key()
86
+ top_uid, top_response = generate_top_response(system_prompt, prompt, api_key)
87
+ benchmark_uid, benchmark_response = generate_benchmark_response(system_prompt, prompt, api_key)
88
+
89
+ return f"TOP_{top_uid}: {top_response}\n\n\nBenchmark_{benchmark_uid}:{benchmark_response}"
90
+
91
+ interface = gr.Interface(
92
+ fn=dynamic_function,
93
+ inputs=[
94
+ gr.inputs.Textbox(label="System Prompt", optional=True),
95
+ gr.inputs.Textbox(label="Enter your question")
96
+ ],
97
+ outputs=gr.outputs.Textbox(label="Responses"),
98
+ title="Bittensor Compare Util",
99
+ )
100
+
101
+
102
+ # Launch the Gradio Interface
103
+ interface.launch(share=False, enable_queue=True)
104
+