Spaces:
Runtime error
Runtime error
Commit
·
9498f26
1
Parent(s):
3c0e1c4
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
+
import gradio as gr
|
3 |
+
import random
|
4 |
+
import prompts
|
5 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
+
|
7 |
+
def format_prompt(message, history):
|
8 |
+
prompt = "<s>"
|
9 |
+
for user_prompt, bot_response in history:
|
10 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
11 |
+
prompt += f" {bot_response}</s> "
|
12 |
+
prompt += f"[INST] {message} [/INST]"
|
13 |
+
return prompt
|
14 |
+
|
15 |
+
def generate(prompt,history)
|
16 |
+
seed = random.randint(1,9999999999999)
|
17 |
+
|
18 |
+
system_prompt = agent.SONG_WRITER
|
19 |
+
generate_kwargs = dict(
|
20 |
+
temperature=0.9,
|
21 |
+
max_new_tokens=1024,
|
22 |
+
top_p=0.95,
|
23 |
+
repetition_penalty=repetition_penalty,
|
24 |
+
do_sample=True,
|
25 |
+
seed=seed,
|
26 |
+
)
|
27 |
+
|
28 |
+
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
29 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
30 |
+
output = ""
|
31 |
+
|
32 |
+
for response in stream:
|
33 |
+
output += response.token.text
|
34 |
+
yield output
|
35 |
+
return output
|