Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,22 +28,34 @@ def generate(prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, r
|
|
28 |
|
29 |
formatted_prompt = format_prompt(prompt, history)
|
30 |
response = client.text_generation(formatted_prompt, **generate_kwargs)
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def main():
|
34 |
-
st.title("Mistral 7B")
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
history = [] # You need to manage the conversation history here
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
st.
|
46 |
-
st.write(output)
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
main()
|
|
|
28 |
|
29 |
formatted_prompt = format_prompt(prompt, history)
|
30 |
response = client.text_generation(formatted_prompt, **generate_kwargs)
|
31 |
+
|
32 |
+
if 'choices' in response:
|
33 |
+
return response['choices'][0]['text']
|
34 |
+
else:
|
35 |
+
return response['text']
|
36 |
|
37 |
def main():
|
38 |
+
st.title("Mistral 7B Chat Interface")
|
39 |
+
|
40 |
+
# Sidebar for adjusting parameters
|
41 |
+
st.sidebar.header("Adjust Parameters")
|
42 |
+
temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.9, step=0.05)
|
43 |
+
max_new_tokens = st.sidebar.slider("Max new tokens", 0, 1048, 256, step=64)
|
44 |
+
top_p = st.sidebar.slider("Top-p (nucleus sampling)", 0.0, 1.0, 0.90, step=0.05)
|
45 |
+
repetition_penalty = st.sidebar.slider("Repetition penalty", 1.0, 2.0, 1.2, step=0.05)
|
46 |
+
|
47 |
+
# Chat interface
|
48 |
+
user_input = st.text_area("User Input:", "")
|
49 |
history = [] # You need to manage the conversation history here
|
50 |
|
51 |
+
if st.button("Send"):
|
52 |
+
history.append(("User", user_input))
|
53 |
+
bot_response = generate(user_input, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
54 |
+
history.append(("Bot", bot_response))
|
55 |
|
56 |
+
st.text("Chat History:")
|
57 |
+
for role, message in history:
|
58 |
+
st.write(f"{role}: {message}")
|
|
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
main()
|