Spaces:
Sleeping
Sleeping
AFischer1985
commited on
Commit
•
308dd86
1
Parent(s):
7af3afe
Update run.py
Browse files
run.py
CHANGED
@@ -1,10 +1,33 @@
|
|
1 |
-
import random
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
return random.choice(["Yes", "No"])
|
6 |
-
|
7 |
-
demo = gr.ChatInterface(random_response)
|
8 |
-
|
9 |
-
if __name__ == "__main__":
|
10 |
-
demo.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import random
|
4 |
+
import json
|
5 |
+
def response(message, history):
|
6 |
+
url="https://afischer1985-wizardlm-13b-v1-2-q4-0-gguf.hf.space/v1/completions"
|
7 |
+
body={"prompt":"###Frage: "+message+" ###Antwort:","max_tokens":1000,"stop":"###","stream":True} #128
|
8 |
+
response=""
|
9 |
+
buffer=""
|
10 |
+
print("User: "+message+"\nAI: ")
|
11 |
+
for text in requests.post(url, json=body, stream=True):
|
12 |
+
#print("*** Raw String: "+str(text)+"\n***\n")
|
13 |
+
text=text.decode('utf-8')
|
14 |
+
if(text.startswith(": ping -")==False):buffer=str(buffer)+str(text)
|
15 |
+
#if(text.startswith(": ping -")): print("\n*** PING!\n***\n")
|
16 |
+
#print("\n*** Buffer: "+str(buffer)+"\n***\n")
|
17 |
+
buffer=buffer.split('"finish_reason"')
|
18 |
+
if(len(buffer)==1):
|
19 |
+
buffer="".join(buffer)
|
20 |
+
pass
|
21 |
+
if(len(buffer)==2):
|
22 |
+
part=buffer[0]+'"finish_reason": null}]}'
|
23 |
+
if(part.startswith("data: ")):part=part.replace("data: ", "")
|
24 |
+
try:
|
25 |
+
part = str(json.loads(part)["choices"][0]["text"])
|
26 |
+
print(part, end="", flush=True)
|
27 |
+
response=response+part
|
28 |
+
buffer="" # reset buffer
|
29 |
+
except:
|
30 |
+
pass
|
31 |
+
yield response
|
32 |
|
33 |
+
gr.ChatInterface(response).queue().launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|