Spaces:
Runtime error
Runtime error
Steven Chen
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import spaces
|
| 4 |
-
from transformers import
|
| 5 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 6 |
from threading import Thread
|
| 7 |
|
| 8 |
# Set an environment variable
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
DESCRIPTION = '''
|
| 13 |
<div>
|
| 14 |
-
<h1 style="text-align: center;">
|
| 15 |
-
<p>This Space demonstrates the instruction-tuned model <a href="https://huggingface.co/
|
| 16 |
-
<p
|
| 17 |
-
<p>🦕 Looking for an even more powerful model? Check out the <a href="https://huggingface.co/chat/"><b>Hugging Chat</b></a> integration for Meta Llama 3 70b</p>
|
| 18 |
</div>
|
| 19 |
'''
|
| 20 |
|
| 21 |
LICENSE = """
|
| 22 |
<p/>
|
| 23 |
---
|
| 24 |
-
Built with
|
| 25 |
"""
|
| 26 |
|
| 27 |
PLACEHOLDER = """
|
| 28 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
| 29 |
-
<
|
| 30 |
-
<
|
| 31 |
-
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
|
| 32 |
</div>
|
| 33 |
"""
|
| 34 |
|
| 35 |
-
|
| 36 |
css = """
|
| 37 |
h1 {
|
| 38 |
text-align: center;
|
|
@@ -48,10 +43,11 @@ h1 {
|
|
| 48 |
|
| 49 |
# Load the tokenizer and model
|
| 50 |
tokenizer = AutoTokenizer.from_pretrained("StevenChen16/llama3-8b-Lawyer")
|
| 51 |
-
model = AutoModelForCausalLM.from_pretrained("StevenChen16/llama3-8b-Lawyer", device_map="auto")
|
|
|
|
| 52 |
terminators = [
|
| 53 |
tokenizer.eos_token_id,
|
| 54 |
-
tokenizer.convert_tokens_to_ids("
|
| 55 |
]
|
| 56 |
|
| 57 |
@spaces.GPU(duration=120)
|
|
@@ -97,12 +93,11 @@ def chat_llama3_8b(message: str,
|
|
| 97 |
outputs = []
|
| 98 |
for text in streamer:
|
| 99 |
outputs.append(text)
|
| 100 |
-
#print(outputs)
|
| 101 |
yield "".join(outputs)
|
| 102 |
|
| 103 |
|
| 104 |
# Gradio block
|
| 105 |
-
chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
| 106 |
|
| 107 |
with gr.Blocks(fill_height=True, css=css) as demo:
|
| 108 |
|
|
@@ -140,4 +135,4 @@ with gr.Blocks(fill_height=True, css=css) as demo:
|
|
| 140 |
gr.Markdown(LICENSE)
|
| 141 |
|
| 142 |
if __name__ == "__main__":
|
| 143 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import spaces
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
|
|
|
| 5 |
from threading import Thread
|
| 6 |
|
| 7 |
# Set an environment variable
|
| 8 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
|
|
| 9 |
|
| 10 |
DESCRIPTION = '''
|
| 11 |
<div>
|
| 12 |
+
<h1 style="text-align: center;">StevenChen16 Llama3 8B Lawyer</h1>
|
| 13 |
+
<p>This Space demonstrates the instruction-tuned model <a href="https://huggingface.co/StevenChen16/llama3-8b-Lawyer"><b>StevenChen16 Llama3 8B Lawyer</b></a>. This model is fine-tuned to provide legal advice based on US and Canada law.</p>
|
| 14 |
+
<p>Feel free to play with it, or duplicate to run privately!</p>
|
|
|
|
| 15 |
</div>
|
| 16 |
'''
|
| 17 |
|
| 18 |
LICENSE = """
|
| 19 |
<p/>
|
| 20 |
---
|
| 21 |
+
Built with StevenChen16 Llama3 8B Lawyer
|
| 22 |
"""
|
| 23 |
|
| 24 |
PLACEHOLDER = """
|
| 25 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
| 26 |
+
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">StevenChen16 Llama3 8B Lawyer</h1>
|
| 27 |
+
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything about US and Canada law...</p>
|
|
|
|
| 28 |
</div>
|
| 29 |
"""
|
| 30 |
|
|
|
|
| 31 |
css = """
|
| 32 |
h1 {
|
| 33 |
text-align: center;
|
|
|
|
| 43 |
|
| 44 |
# Load the tokenizer and model
|
| 45 |
tokenizer = AutoTokenizer.from_pretrained("StevenChen16/llama3-8b-Lawyer")
|
| 46 |
+
model = AutoModelForCausalLM.from_pretrained("StevenChen16/llama3-8b-Lawyer", device_map="auto")
|
| 47 |
+
|
| 48 |
terminators = [
|
| 49 |
tokenizer.eos_token_id,
|
| 50 |
+
tokenizer.convert_tokens_to_ids("")
|
| 51 |
]
|
| 52 |
|
| 53 |
@spaces.GPU(duration=120)
|
|
|
|
| 93 |
outputs = []
|
| 94 |
for text in streamer:
|
| 95 |
outputs.append(text)
|
|
|
|
| 96 |
yield "".join(outputs)
|
| 97 |
|
| 98 |
|
| 99 |
# Gradio block
|
| 100 |
+
chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
| 101 |
|
| 102 |
with gr.Blocks(fill_height=True, css=css) as demo:
|
| 103 |
|
|
|
|
| 135 |
gr.Markdown(LICENSE)
|
| 136 |
|
| 137 |
if __name__ == "__main__":
|
| 138 |
+
demo.launch()
|