Spaces:
Runtime error
Runtime error
Commit
·
66611f3
1
Parent(s):
960cd05
Update app.py
Browse files
app.py
CHANGED
@@ -30,85 +30,6 @@ from huggingface_hub import hf_hub_download
|
|
30 |
from huggingface_hub import login
|
31 |
from datasets import load_dataset
|
32 |
|
33 |
-
client = InferenceClient(
|
34 |
-
"mistralai/Mistral-7B-Instruct-v0.1"
|
35 |
-
)
|
36 |
-
|
37 |
-
|
38 |
-
def format_prompt(message, history):
|
39 |
-
prompt = "<s>"
|
40 |
-
for user_prompt, bot_response in history:
|
41 |
-
prompt += f"[INST] {user_prompt} [/INST]"
|
42 |
-
prompt += f" {bot_response}</s> "
|
43 |
-
prompt += f"[INST] {message} [/INST]"
|
44 |
-
return prompt
|
45 |
-
|
46 |
-
def generate(
|
47 |
-
prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
48 |
-
):
|
49 |
-
temperature = float(temperature)
|
50 |
-
if temperature < 1e-2:
|
51 |
-
temperature = 1e-2
|
52 |
-
top_p = float(top_p)
|
53 |
-
|
54 |
-
generate_kwargs = dict(
|
55 |
-
temperature=temperature,
|
56 |
-
max_new_tokens=max_new_tokens,
|
57 |
-
top_p=top_p,
|
58 |
-
repetition_penalty=repetition_penalty,
|
59 |
-
do_sample=True,
|
60 |
-
seed=42,
|
61 |
-
)
|
62 |
-
|
63 |
-
formatted_prompt = format_prompt(prompt, history)
|
64 |
-
|
65 |
-
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
66 |
-
output = ""
|
67 |
-
|
68 |
-
for response in stream:
|
69 |
-
output += response.token.text
|
70 |
-
yield output
|
71 |
-
return output
|
72 |
-
|
73 |
-
|
74 |
-
additional_inputs=[
|
75 |
-
gr.Slider(
|
76 |
-
label="Temperature",
|
77 |
-
value=0.9,
|
78 |
-
minimum=0.0,
|
79 |
-
maximum=1.0,
|
80 |
-
step=0.05,
|
81 |
-
interactive=True,
|
82 |
-
info="Higher values produce more diverse outputs",
|
83 |
-
),
|
84 |
-
gr.Slider(
|
85 |
-
label="Max new tokens",
|
86 |
-
value=256,
|
87 |
-
minimum=0,
|
88 |
-
maximum=5000,
|
89 |
-
step=64,
|
90 |
-
interactive=True,
|
91 |
-
info="The maximum numbers of new tokens",
|
92 |
-
),
|
93 |
-
gr.Slider(
|
94 |
-
label="Top-p (nucleus sampling)",
|
95 |
-
value=0.90,
|
96 |
-
minimum=0.0,
|
97 |
-
maximum=1,
|
98 |
-
step=0.05,
|
99 |
-
interactive=True,
|
100 |
-
info="Higher values sample more low-probability tokens",
|
101 |
-
),
|
102 |
-
gr.Slider(
|
103 |
-
label="Repetition penalty",
|
104 |
-
value=1.2,
|
105 |
-
minimum=1.0,
|
106 |
-
maximum=2.0,
|
107 |
-
step=0.05,
|
108 |
-
interactive=True,
|
109 |
-
info="Penalize repeated tokens",
|
110 |
-
)
|
111 |
-
]
|
112 |
|
113 |
#dataset = load_dataset("csv", data_files="./data.csv")
|
114 |
|
@@ -176,12 +97,20 @@ def ccogsphere(name: str, rate: str, celsci: str):
|
|
176 |
"Name" : ["Video 1", "Video 2", "Video 3", "Video 4", "Video 5"],
|
177 |
"Views" : [500, 2000, 540, 300, 200],
|
178 |
"Duration" : [30, 20, 70, 35, 22]})
|
179 |
-
name1=name.split()
|
|
|
180 |
try:
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
if name[1]==None:
|
184 |
-
nam="you wrote no messages..."
|
185 |
mess="No messages..."
|
186 |
except:
|
187 |
nam="No name, write your name followed by a message"
|
|
|
30 |
from huggingface_hub import login
|
31 |
from datasets import load_dataset
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
#dataset = load_dataset("csv", data_files="./data.csv")
|
35 |
|
|
|
97 |
"Name" : ["Video 1", "Video 2", "Video 3", "Video 4", "Video 5"],
|
98 |
"Views" : [500, 2000, 540, 300, 200],
|
99 |
"Duration" : [30, 20, 70, 35, 22]})
|
100 |
+
name1=name.split(":")
|
101 |
+
mess=name1[1]
|
102 |
try:
|
103 |
+
client = Client("https://osaaso-mistral-7b-instruct.hf.space/")
|
104 |
+
result = client.predict(
|
105 |
+
mess,
|
106 |
+
0,
|
107 |
+
0,
|
108 |
+
0,
|
109 |
+
1,
|
110 |
+
api_name="/chat"
|
111 |
+
)
|
112 |
+
nam=result.json() #name1[0]
|
113 |
if name[1]==None:
|
|
|
114 |
mess="No messages..."
|
115 |
except:
|
116 |
nam="No name, write your name followed by a message"
|