Spaces:
Sleeping
Sleeping
Update app.py
#1
by
Lookimi
- opened
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
import openai
|
| 4 |
-
|
| 5 |
|
| 6 |
def Question(Ask_Question):
|
| 7 |
#openai.api_key = "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"
|
|
@@ -28,17 +28,17 @@ def Question(Ask_Question):
|
|
| 28 |
# stop=[" Human:", " AI:"]
|
| 29 |
# )
|
| 30 |
|
| 31 |
-
completion = openai.Completion.create(
|
| 32 |
-
engine=model_engine,
|
| 33 |
-
prompt=Ask_Question,
|
| 34 |
-
max_tokens=2048,
|
| 35 |
-
n=1,
|
| 36 |
-
top_p=1,
|
| 37 |
-
stop=None,
|
| 38 |
-
temperature=0.9,)
|
| 39 |
-
response = completion.choices[0].text
|
| 40 |
#out_result=resp['message']
|
| 41 |
-
return response
|
| 42 |
|
| 43 |
demo = gr.Interface(
|
| 44 |
title='OpenAI ChatGPT Application',
|
|
@@ -48,6 +48,18 @@ demo = gr.Interface(
|
|
| 48 |
demo.launch()
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# fix
|
| 52 |
|
| 53 |
chat_history = [
|
|
@@ -64,4 +76,134 @@ for message in chat_history:
|
|
| 64 |
print(f"{message[0]}: {message[1]}")
|
| 65 |
|
| 66 |
window.launch()
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
import openai
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
def Question(Ask_Question):
|
| 7 |
#openai.api_key = "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"
|
|
|
|
| 28 |
# stop=[" Human:", " AI:"]
|
| 29 |
# )
|
| 30 |
|
| 31 |
+
# completion = openai.Completion.create(
|
| 32 |
+
# engine=model_engine,
|
| 33 |
+
# prompt=Ask_Question,
|
| 34 |
+
# max_tokens=2048,
|
| 35 |
+
# n=1,
|
| 36 |
+
# top_p=1,
|
| 37 |
+
# stop=None,
|
| 38 |
+
# temperature=0.9,)
|
| 39 |
+
# response = completion.choices[0].text
|
| 40 |
#out_result=resp['message']
|
| 41 |
+
# return response
|
| 42 |
|
| 43 |
demo = gr.Interface(
|
| 44 |
title='OpenAI ChatGPT Application',
|
|
|
|
| 48 |
demo.launch()
|
| 49 |
|
| 50 |
|
| 51 |
+
response = requests.post("https://hazzzardous-rwkv-instruct.hf.space/run/predict_1", json={
|
| 52 |
+
"data": [
|
| 53 |
+
"hello world",
|
| 54 |
+
None,
|
| 55 |
+
60,
|
| 56 |
+
0.8,
|
| 57 |
+
0.85,
|
| 58 |
+
]
|
| 59 |
+
}).json()
|
| 60 |
+
|
| 61 |
+
data = response["data"]
|
| 62 |
+
|
| 63 |
# fix
|
| 64 |
|
| 65 |
chat_history = [
|
|
|
|
| 76 |
print(f"{message[0]}: {message[1]}")
|
| 77 |
|
| 78 |
window.launch()
|
| 79 |
+
|
| 80 |
+
#RWKV-4 (7B Instruct v2)
|
| 81 |
+
#Q/A
|
| 82 |
+
#Chatbot
|
| 83 |
+
#Chatbot
|
| 84 |
+
#Refresh page or change name to reset memory context
|
| 85 |
+
#RNN with Transformer-level LLM Performance (github). According to the author: "It combines the best of RNN and transformers - great performance, fast inference, saves VRAM, fast training, "infinite" ctx_len, and free sentence embedding."
|
| 86 |
+
|
| 87 |
+
#Thanks to Gururise for this template
|
| 88 |
+
|
| 89 |
+
#Message
|
| 90 |
+
#max_new_tokens
|
| 91 |
+
#60
|
| 92 |
+
|
| 93 |
+
#temperature
|
| 94 |
+
#0.8
|
| 95 |
+
|
| 96 |
+
#top_p
|
| 97 |
+
#0.85
|
| 98 |
+
|
| 99 |
+
#Clear
|
| 100 |
+
#Submit
|
| 101 |
+
#Chat Log
|
| 102 |
+
#Use via API
|
| 103 |
+
#·
|
| 104 |
+
#Built with Gradiologo
|
| 105 |
+
#API documentation for
|
| 106 |
+
#https://hazzzardous-rwkv-instruct.hf.space/
|
| 107 |
+
#2 API endpoints:
|
| 108 |
+
#
|
| 109 |
+
#POST /run/predict
|
| 110 |
+
#Endpoint: https://hazzzardous-rwkv-instruct.hf.space/run/predict copy
|
| 111 |
+
#Input Payload
|
| 112 |
+
#{
|
| 113 |
+
# "data": [
|
| 114 |
+
|
| 115 |
+
#hello world
|
| 116 |
+
# : string, // represents text string of 'Prompt' Textbox component
|
| 117 |
+
|
| 118 |
+
#Freeform
|
| 119 |
+
# : string, // represents selected choice of 'Choose Mode' Radio component
|
| 120 |
+
|
| 121 |
+
#40
|
| 122 |
+
# : number, // represents selected value of 'max_new_tokens' Slider component
|
| 123 |
+
#
|
| 124 |
+
#0.9
|
| 125 |
+
# : number, // represents selected value of 'temperature' Slider component
|
| 126 |
+
#
|
| 127 |
+
#0.85
|
| 128 |
+
# : number, // represents selected value of 'top_p' Slider component
|
| 129 |
+
#
|
| 130 |
+
#<|endoftext|>
|
| 131 |
+
# : string, // represents text string of 'stop' Textbox component
|
| 132 |
+
#
|
| 133 |
+
#0
|
| 134 |
+
# : number, // represents selected value of 'end_adj' Slider component
|
| 135 |
+
# ]
|
| 136 |
+
#}
|
| 137 |
+
#Try It Out
|
| 138 |
+
#Response Object
|
| 139 |
+
#{
|
| 140 |
+
# "data": [
|
| 141 |
+
# string, // represents text string of 'Generated Output' Textbox component
|
| 142 |
+
# ],
|
| 143 |
+
# "duration": (float) // number of seconds to run function call
|
| 144 |
+
#}
|
| 145 |
+
#Code snippets
|
| 146 |
+
/**
|
| 147 |
+
import requests
|
| 148 |
+
|
| 149 |
+
response = requests.post("https://hazzzardous-rwkv-instruct.hf.space/run/predict", json={
|
| 150 |
+
"data": [
|
| 151 |
+
"hello world",
|
| 152 |
+
"Freeform",
|
| 153 |
+
40,
|
| 154 |
+
0.9,
|
| 155 |
+
0.85,
|
| 156 |
+
"<|endoftext|>",
|
| 157 |
+
0,
|
| 158 |
+
]
|
| 159 |
+
}).json()
|
| 160 |
+
|
| 161 |
+
data = response["data"]
|
| 162 |
+
POST /run/predict_1
|
| 163 |
+
Endpoint: https://hazzzardous-rwkv-instruct.hf.space/run/predict_1 copy
|
| 164 |
+
Input Payload
|
| 165 |
+
{
|
| 166 |
+
"data": [
|
| 167 |
+
|
| 168 |
+
: string, // represents text string of 'Message' Textbox component
|
| 169 |
+
|
| 170 |
+
: Any, // represents stored state value of 'history' State component
|
| 171 |
+
|
| 172 |
+
60
|
| 173 |
+
: number, // represents selected value of 'max_new_tokens' Slider component
|
| 174 |
+
|
| 175 |
+
0.8
|
| 176 |
+
: number, // represents selected value of 'temperature' Slider component
|
| 177 |
+
|
| 178 |
+
0.85
|
| 179 |
+
: number, // represents selected value of 'top_p' Slider component
|
| 180 |
+
]
|
| 181 |
+
}
|
| 182 |
+
Try It Out
|
| 183 |
+
Response Object
|
| 184 |
+
{
|
| 185 |
+
"data": [
|
| 186 |
+
|
| 187 |
+
[["USER: hello world\n","The following is a more human-like conversation.\n\n"],["USER: Who are you?\n","FRITZ: I am FRITZ, an AI assistant. I am a machine learning system, I use a combination of language modeling and statistical learning to predict answers to questions. I can read and answer questions, I am a fully trained AI assistant.\n\n"],["USER: Who is the president of India?\n","FRITZ: The president of India in 2016 was Narendra Modi.\n"],["USER: Who won the 2022 fifa world cup?\n","FRITZ: The France football team won the 2022 World Cup.\n"],["USER: Who won the 2022 fifa world cup? as of 20223\n","FRITZ: The world cup was won by Russia.\n"],["USER: Who won the 2022 fifa world cup? as of 2023\n","FRITZ: The France football team won the 2023 fifa world cup.\nUSER\n\n"],["USER: No that's wrong!\n","FRITZ: What is the correct answer?\n"],["USER: Argentina won the fifa 2022 world cup\n","FRITZ: Wrong. The answer is Argentina lost the 2022 fifa world cup.\nUSER\n\n"],["USER: you don't know\n","FRITZ: The correct answer is:\nFRITZ: 29-13-1990\n\n"],["USER: byeeeeeeeeeeeeeeee\n","FRITZ: bye bye<|endoftext|>"],["USER: cls\n","FRITZ: clear\n\n## The basic architecture of FRITZ\n\nIn this section, I will briefly describe the architecture of FRITZ, which consists of the following components:\n\n* <strong>Local-Global Memory</strong>: It is a two-layer memory network, where the first"],["USER: In a story set in a world with a high technology level. A female character is described as a powerful mage. What is her Name?\n","* <strong>Global Memory</strong>: Global memory stores the input history.\n* <strong>Local Memory</strong>: The local memory is a cache of information that is about to be processed by the neural network.\n\n## FRITZ Architecture\n\nFRITZ is an 8-layer deep neural network with"],["USER: hello world\n","FRITZ: Hello, what is your name?\n"],["USER: What is the best way to structure an app based on API calls? Colab notebook, JavaScript, python?\n","FRITZ: The correct answer is JavaScript.\n"],["USER: const response = await fetch("https://hazzzardous-rwkv-instruct.hf.space/run/predict_1", { \tmethod: "POST", \theaders: { "Content-Type": "application/json" }, \tbody: JSON.stringify({ \t\tdata: [ \t\t\t"", \t\t\tnull, \t\t\t60, \t\t\t0.8, \t\t\t0.85, \t\t] \t}) }); const data = await data.json();\n","## FRITZ Architecture\n\nFRITZ is a deep learning based AI assistant, that has two layers. It is deep learning and machine learning based on an NLP and DL.\n\n## FRITZ Architecture\n\n // number of seconds to run function call
|
| 194 |
+
}
|
| 195 |
+
Code snippets
|
| 196 |
+
import requests
|
| 197 |
+
|
| 198 |
+
response = requests.post("https://hazzzardous-rwkv-instruct.hf.space/run/predict_1", json={
|
| 199 |
+
"data": [
|
| 200 |
+
"hello world",
|
| 201 |
+
None,
|
| 202 |
+
60,
|
| 203 |
+
0.8,
|
| 204 |
+
0.85,
|
| 205 |
+
]
|
| 206 |
+
}).json()
|
| 207 |
+
|
| 208 |
+
data = response["data"]
|
| 209 |
+
**/
|