Spaces:
Runtime error
Runtime error
Steven Chen
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ DESCRIPTION = '''
|
|
| 16 |
LICENSE = """
|
| 17 |
<p/>
|
| 18 |
---
|
| 19 |
-
Built with model "StevenChen16/
|
| 20 |
"""
|
| 21 |
|
| 22 |
PLACEHOLDER = """
|
|
@@ -37,26 +37,6 @@ h1 {
|
|
| 37 |
background: #1565c0;
|
| 38 |
border-radius: 100vh;
|
| 39 |
}
|
| 40 |
-
.chat-message {
|
| 41 |
-
display: flex;
|
| 42 |
-
align-items: flex-start;
|
| 43 |
-
margin-bottom: 10px;
|
| 44 |
-
}
|
| 45 |
-
.chat-message img {
|
| 46 |
-
width: 40px;
|
| 47 |
-
height: 40px;
|
| 48 |
-
margin-right: 10px;
|
| 49 |
-
border-radius: 50%;
|
| 50 |
-
}
|
| 51 |
-
.chat-message .message {
|
| 52 |
-
max-width: 80%;
|
| 53 |
-
background-color: #f1f1f1;
|
| 54 |
-
padding: 10px;
|
| 55 |
-
border-radius: 10px;
|
| 56 |
-
}
|
| 57 |
-
.me .message {
|
| 58 |
-
background-color: #d1e7ff;
|
| 59 |
-
}
|
| 60 |
"""
|
| 61 |
|
| 62 |
args = dict(
|
|
@@ -106,37 +86,26 @@ def query_model(user_input, history):
|
|
| 106 |
for new_text in chat_model.stream_chat(messages, max_new_tokens=512, temperature=0.9):
|
| 107 |
response += new_text
|
| 108 |
yield response
|
| 109 |
-
|
| 110 |
-
# 格式化消息
|
| 111 |
-
def format_message(role, content):
|
| 112 |
-
if role == 'user':
|
| 113 |
-
avatar = '<div class="chat-message me"><img src="data:image/svg+xml,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 100 100\'><rect width=\'100\' height=\'100\' fill=\'black\'/><text x=\'50%\' y=\'50%\' fill=\'white\' font-size=\'50\' text-anchor=\'middle\' alignment-baseline=\'central\'>Me</text></svg>" />'
|
| 114 |
-
else:
|
| 115 |
-
avatar = '<div class="chat-message"><img src="avatar.png" />'
|
| 116 |
-
return f'{avatar}<div class="message">{content}</div></div>'
|
| 117 |
-
|
| 118 |
# Gradio block
|
| 119 |
chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
| 120 |
|
| 121 |
with gr.Blocks(css=css) as demo:
|
| 122 |
gr.Markdown(DESCRIPTION)
|
| 123 |
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
send_button.click(respond, [input_text, chatbot], [chatbot, chatbot])
|
| 138 |
-
|
| 139 |
gr.Markdown(LICENSE)
|
| 140 |
|
| 141 |
if __name__ == "__main__":
|
| 142 |
-
demo.launch(
|
|
|
|
| 16 |
LICENSE = """
|
| 17 |
<p/>
|
| 18 |
---
|
| 19 |
+
Built with model "StevenChen16/Llama3-8B-Lawyer", based on "meta-llama/Meta-Llama-3-8B"
|
| 20 |
"""
|
| 21 |
|
| 22 |
PLACEHOLDER = """
|
|
|
|
| 37 |
background: #1565c0;
|
| 38 |
border-radius: 100vh;
|
| 39 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
"""
|
| 41 |
|
| 42 |
args = dict(
|
|
|
|
| 86 |
for new_text in chat_model.stream_chat(messages, max_new_tokens=512, temperature=0.9):
|
| 87 |
response += new_text
|
| 88 |
yield response
|
| 89 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
# Gradio block
|
| 91 |
chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
| 92 |
|
| 93 |
with gr.Blocks(css=css) as demo:
|
| 94 |
gr.Markdown(DESCRIPTION)
|
| 95 |
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
| 96 |
+
gr.ChatInterface(
|
| 97 |
+
fn=query_model,
|
| 98 |
+
chatbot=chatbot,
|
| 99 |
+
examples=[
|
| 100 |
+
['What are the key differences between a sole proprietorship and a partnership?'],
|
| 101 |
+
['What legal steps should I take if I want to start a business in the US?'],
|
| 102 |
+
['Can you explain the concept of "duty of care" in negligence law?'],
|
| 103 |
+
['What are the legal requirements for obtaining a patent in Canada?'],
|
| 104 |
+
['How can I protect my intellectual property when sharing my idea with potential investors?']
|
| 105 |
+
],
|
| 106 |
+
cache_examples=False,
|
| 107 |
+
)
|
|
|
|
|
|
|
|
|
|
| 108 |
gr.Markdown(LICENSE)
|
| 109 |
|
| 110 |
if __name__ == "__main__":
|
| 111 |
+
demo.launch()
|