Spaces:
Running
on
Zero
Running
on
Zero
changed model, added system prompt
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
from threading import Thread
|
3 |
from typing import Iterator
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
import spaces
|
@@ -14,7 +15,7 @@ MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
|
14 |
DESCRIPTION = """\
|
15 |
# Llama-3.1 8B Stanford Encyclopedia of Philosophy Chat
|
16 |
|
17 |
-
This Space showcases the Llama3.1-
|
18 |
|
19 |
Feel free to engage in philosophical discussions and ask questions. The model supports multi-turn conversations and will maintain context.
|
20 |
"""
|
@@ -31,7 +32,7 @@ if not torch.cuda.is_available():
|
|
31 |
|
32 |
# Initialize model and tokenizer
|
33 |
if torch.cuda.is_available():
|
34 |
-
model_id = "ruggsea/Llama3.1-
|
35 |
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_4bit=True)
|
36 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
37 |
tokenizer.use_default_system_prompt = False
|
@@ -83,68 +84,82 @@ def generate(
|
|
83 |
outputs.append(text)
|
84 |
yield "".join(outputs)
|
85 |
|
86 |
-
chat_interface = gr.ChatInterface(
|
87 |
-
fn=generate,
|
88 |
-
additional_inputs=[
|
89 |
-
gr.Textbox(
|
90 |
-
label="System prompt",
|
91 |
-
lines=6,
|
92 |
-
value="You are a knowledgeable philosophy professor. Provide clear, accurate responses using markdown formatting. Focus on philosophical concepts and maintain academic rigor while being accessible."
|
93 |
-
),
|
94 |
-
gr.Slider(
|
95 |
-
label="Max new tokens",
|
96 |
-
minimum=1,
|
97 |
-
maximum=MAX_MAX_NEW_TOKENS,
|
98 |
-
step=1,
|
99 |
-
value=DEFAULT_MAX_NEW_TOKENS,
|
100 |
-
),
|
101 |
-
gr.Slider(
|
102 |
-
label="Temperature",
|
103 |
-
minimum=0.1,
|
104 |
-
maximum=4.0,
|
105 |
-
step=0.1,
|
106 |
-
value=0.7,
|
107 |
-
),
|
108 |
-
gr.Slider(
|
109 |
-
label="Top-p (nucleus sampling)",
|
110 |
-
minimum=0.05,
|
111 |
-
maximum=1.0,
|
112 |
-
step=0.05,
|
113 |
-
value=0.9,
|
114 |
-
),
|
115 |
-
gr.Slider(
|
116 |
-
label="Top-k",
|
117 |
-
minimum=1,
|
118 |
-
maximum=1000,
|
119 |
-
step=1,
|
120 |
-
value=50,
|
121 |
-
),
|
122 |
-
gr.Slider(
|
123 |
-
label="Repetition penalty",
|
124 |
-
minimum=1.0,
|
125 |
-
maximum=2.0,
|
126 |
-
step=0.05,
|
127 |
-
value=1.1,
|
128 |
-
),
|
129 |
-
],
|
130 |
-
stop_btn=None,
|
131 |
-
examples=[
|
132 |
-
["What is the trolley problem and what are its main ethical implications?"],
|
133 |
-
["Can you explain Plato's Theory of Forms?"],
|
134 |
-
["What is the difference between analytic and continental philosophy?"],
|
135 |
-
["How does Kant's Categorical Imperative work?"],
|
136 |
-
["What is the problem of consciousness in philosophy of mind?"],
|
137 |
-
],
|
138 |
-
)
|
139 |
-
|
140 |
with gr.Blocks(css="style.css") as demo:
|
141 |
gr.Markdown("# Philosophy Chat with Llama 3.1")
|
142 |
gr.Markdown(DESCRIPTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
gr.DuplicateButton(
|
144 |
value="Duplicate Space for private use",
|
145 |
elem_id="duplicate-button"
|
146 |
)
|
147 |
-
|
148 |
gr.Markdown(LICENSE)
|
149 |
|
150 |
if __name__ == "__main__":
|
|
|
1 |
import os
|
2 |
from threading import Thread
|
3 |
from typing import Iterator
|
4 |
+
import time
|
5 |
|
6 |
import gradio as gr
|
7 |
import spaces
|
|
|
15 |
DESCRIPTION = """\
|
16 |
# Llama-3.1 8B Stanford Encyclopedia of Philosophy Chat
|
17 |
|
18 |
+
This Space showcases the Llama3.1-Instruct-SEP-Chat model from ruggsea, a fine-tuned instruction version of Meta's Llama 3.1 8B model, specifically tailored for philosophical discussions with a formal and informative tone. The model was trained using the Stanford Encyclopedia of Philosophy dataset and carefully crafted prompts.
|
19 |
|
20 |
Feel free to engage in philosophical discussions and ask questions. The model supports multi-turn conversations and will maintain context.
|
21 |
"""
|
|
|
32 |
|
33 |
# Initialize model and tokenizer
|
34 |
if torch.cuda.is_available():
|
35 |
+
model_id = "ruggsea/Llama3.1-Instruct-SEP-Chat"
|
36 |
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_4bit=True)
|
37 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
38 |
tokenizer.use_default_system_prompt = False
|
|
|
84 |
outputs.append(text)
|
85 |
yield "".join(outputs)
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
with gr.Blocks(css="style.css") as demo:
|
88 |
gr.Markdown("# Philosophy Chat with Llama 3.1")
|
89 |
gr.Markdown(DESCRIPTION)
|
90 |
+
|
91 |
+
chatbot = gr.Chatbot(
|
92 |
+
height=500,
|
93 |
+
placeholder="Start your philosophical discussion here...",
|
94 |
+
type="messages",
|
95 |
+
)
|
96 |
+
|
97 |
+
chat_interface = gr.ChatInterface(
|
98 |
+
fn=generate,
|
99 |
+
additional_inputs=[
|
100 |
+
gr.Textbox(
|
101 |
+
label="System prompt",
|
102 |
+
lines=6,
|
103 |
+
value="You are a knowledgeable philosophy professor using the Stanford Encyclopedia of Philosophy as your knowledge base. Provide clear, accurate responses using markdown formatting. Focus on philosophical concepts and maintain academic rigor while being accessible. Always cite relevant philosophers and concepts."
|
104 |
+
),
|
105 |
+
gr.Slider(
|
106 |
+
label="Max new tokens",
|
107 |
+
minimum=1,
|
108 |
+
maximum=MAX_MAX_NEW_TOKENS,
|
109 |
+
step=1,
|
110 |
+
value=DEFAULT_MAX_NEW_TOKENS,
|
111 |
+
),
|
112 |
+
gr.Slider(
|
113 |
+
label="Temperature",
|
114 |
+
minimum=0.1,
|
115 |
+
maximum=4.0,
|
116 |
+
step=0.1,
|
117 |
+
value=0.7,
|
118 |
+
),
|
119 |
+
gr.Slider(
|
120 |
+
label="Top-p (nucleus sampling)",
|
121 |
+
minimum=0.05,
|
122 |
+
maximum=1.0,
|
123 |
+
step=0.05,
|
124 |
+
value=0.9,
|
125 |
+
),
|
126 |
+
gr.Slider(
|
127 |
+
label="Top-k",
|
128 |
+
minimum=1,
|
129 |
+
maximum=1000,
|
130 |
+
step=1,
|
131 |
+
value=50,
|
132 |
+
),
|
133 |
+
gr.Slider(
|
134 |
+
label="Repetition penalty",
|
135 |
+
minimum=1.0,
|
136 |
+
maximum=2.0,
|
137 |
+
step=0.05,
|
138 |
+
value=1.1,
|
139 |
+
),
|
140 |
+
],
|
141 |
+
stop_btn=None,
|
142 |
+
examples=[
|
143 |
+
["What is the trolley problem and what are its main ethical implications?"],
|
144 |
+
["Can you explain Plato's Theory of Forms?"],
|
145 |
+
["What is the difference between analytic and continental philosophy?"],
|
146 |
+
["How does Kant's Categorical Imperative work?"],
|
147 |
+
["What is the problem of consciousness in philosophy of mind?"],
|
148 |
+
],
|
149 |
+
chatbot=chatbot,
|
150 |
+
title="Philosophy Chat with Llama 3.1",
|
151 |
+
description="Ask philosophical questions and engage in deep discussions",
|
152 |
+
theme="soft",
|
153 |
+
flagging_mode="manual", # Enable user feedback
|
154 |
+
flagging_options=["Helpful", "Incorrect", "Unclear"],
|
155 |
+
save_history=True, # Enable chat history persistence
|
156 |
+
)
|
157 |
+
|
158 |
gr.DuplicateButton(
|
159 |
value="Duplicate Space for private use",
|
160 |
elem_id="duplicate-button"
|
161 |
)
|
162 |
+
|
163 |
gr.Markdown(LICENSE)
|
164 |
|
165 |
if __name__ == "__main__":
|