Spaces:
Runtime error
Runtime error
Commit
·
84fadff
1
Parent(s):
8a0ed94
Upload folder using huggingface_hub
Browse files- danskgpt-chat/main.py +65 -0
danskgpt-chat/main.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import random
|
5 |
+
def http_bot(prompt, history, system_prompt, endpoint_url):
|
6 |
+
# Initialize the formatted_chat string with the system prompt
|
7 |
+
formatted_chat = f"{system_prompt}\n"
|
8 |
+
|
9 |
+
# Append previous history if available
|
10 |
+
if history:
|
11 |
+
for user_text, assistant_text in history:
|
12 |
+
formatted_chat += f"USER: {user_text}\nASSISTANT: {assistant_text}\n"
|
13 |
+
|
14 |
+
# Add the current prompt and assistant placeholder
|
15 |
+
formatted_chat += f"USER: {prompt}\nASSISTANT: "
|
16 |
+
print(formatted_chat)
|
17 |
+
|
18 |
+
headers = {"User-Agent": "vLLM Client"}
|
19 |
+
pload = {
|
20 |
+
"prompt": formatted_chat,
|
21 |
+
"stream": True,
|
22 |
+
"max_tokens": 3000,
|
23 |
+
}
|
24 |
+
|
25 |
+
|
26 |
+
response = requests.post(endpoint_url,
|
27 |
+
headers=headers,
|
28 |
+
json=pload,
|
29 |
+
stream=True)
|
30 |
+
|
31 |
+
for chunk in response.iter_lines(chunk_size=8192,
|
32 |
+
decode_unicode=False,
|
33 |
+
delimiter=b"\0"):
|
34 |
+
if chunk:
|
35 |
+
data = json.loads(chunk.decode("utf-8"))
|
36 |
+
output = data["text"][0]
|
37 |
+
|
38 |
+
yield output[len(prompt):]
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="DanskGPT") as demo:
|
44 |
+
gr.Markdown("# DanskGPT v0.3 - offline. Hvis du vil have en demo, så kontakt mig. Kontaktinformation nederst.")
|
45 |
+
gr.Markdown("Et dansk alternativ til ChatGPT der kører lokalt.")
|
46 |
+
system_prompt = gr.Textbox(value="Du er en dansk AI-assistent. Du vil blive givet en opgave. Du skal hjælpe så meget du kan.",
|
47 |
+
label="System besked")
|
48 |
+
endpoint_url = gr.Textbox(label="Endpoint url", value="https://h6lsu4k84eqhh4-8000.proxy.runpod.net/generate", render=False)
|
49 |
+
|
50 |
+
|
51 |
+
gr.ChatInterface(
|
52 |
+
http_bot,
|
53 |
+
additional_inputs=[system_prompt, endpoint_url],
|
54 |
+
clear_btn=None,
|
55 |
+
undo_btn=None,
|
56 |
+
retry_btn=None,
|
57 |
+
submit_btn="Send",
|
58 |
+
|
59 |
+
)
|
60 |
+
|
61 |
+
gr.Markdown("Version 0.3 - instruktionsmodel trænet på data op til 31-06-2023.")
|
62 |
+
gr.Markdown("Lavet af Mads Henrichsen - Kontakt: [email protected]")
|
63 |
+
gr.Markdown("Bemærk: DanskGPT producerer ikke nødvendigvis sandfærdig information - der er en ny model på vej der er meget bedre til dette.")
|
64 |
+
|
65 |
+
demo.queue(concurrency_count=100).launch()
|