Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,16 +5,10 @@ from transformers import GemmaTokenizer, AutoModelForCausalLM
|
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 6 |
from threading import Thread
|
| 7 |
|
| 8 |
-
# Set an environment variable
|
| 9 |
-
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 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/meta-llama/Meta-Llama-3-8B-Instruct"><b>Meta Llama3 8b Chat</b></a>. Meta Llama3 is the new open LLM and comes in two sizes: 8b and 70b. Feel free to play with it, or duplicate to run privately!</p>
|
| 16 |
-
<p>🔎 For more details about the Llama3 release and how to use the model with <code>transformers</code>, take a look <a href="https://huggingface.co/blog/llama3">at our blog post</a>.</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 |
|
|
@@ -22,13 +16,13 @@ LICENSE = """
|
|
| 22 |
<p/>
|
| 23 |
|
| 24 |
---
|
| 25 |
-
Built with
|
| 26 |
"""
|
| 27 |
|
| 28 |
PLACEHOLDER = """
|
| 29 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
| 30 |
-
<img src="https://
|
| 31 |
-
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">
|
| 32 |
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
|
| 33 |
</div>
|
| 34 |
"""
|
|
@@ -46,24 +40,30 @@ h1 {
|
|
| 46 |
background: #1565c0;
|
| 47 |
border-radius: 100vh;
|
| 48 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
"""
|
| 50 |
|
| 51 |
# Load the tokenizer and model
|
| 52 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
| 53 |
-
model = AutoModelForCausalLM.from_pretrained("
|
| 54 |
terminators = [
|
| 55 |
tokenizer.eos_token_id,
|
| 56 |
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 57 |
]
|
| 58 |
|
| 59 |
@spaces.GPU(duration=120)
|
| 60 |
-
def
|
| 61 |
history: list,
|
| 62 |
temperature: float,
|
| 63 |
max_new_tokens: int
|
| 64 |
) -> str:
|
| 65 |
"""
|
| 66 |
-
Generate a streaming response using the
|
| 67 |
Args:
|
| 68 |
message (str): The input message.
|
| 69 |
history (list): The conversation history used by ChatInterface.
|
|
@@ -104,14 +104,14 @@ def chat_llama3_8b(message: str,
|
|
| 104 |
|
| 105 |
|
| 106 |
# Gradio block
|
| 107 |
-
chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER,
|
| 108 |
|
| 109 |
with gr.Blocks(fill_height=True, css=css) as demo:
|
| 110 |
|
| 111 |
gr.Markdown(DESCRIPTION)
|
| 112 |
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
| 113 |
gr.ChatInterface(
|
| 114 |
-
fn=
|
| 115 |
chatbot=chatbot,
|
| 116 |
fill_height=True,
|
| 117 |
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
|
|
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 6 |
from threading import Thread
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
DESCRIPTION = '''
|
| 10 |
<div>
|
| 11 |
+
<h1 style="text-align: center;">OpenChat 3.6</h1>
|
|
|
|
|
|
|
|
|
|
| 12 |
</div>
|
| 13 |
'''
|
| 14 |
|
|
|
|
| 16 |
<p/>
|
| 17 |
|
| 18 |
---
|
| 19 |
+
Built with OpenChat 3.6
|
| 20 |
"""
|
| 21 |
|
| 22 |
PLACEHOLDER = """
|
| 23 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
| 24 |
+
<img src="https://raw.githubusercontent.com/imoneoi/openchat/master/assets/logo_new.png" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
|
| 25 |
+
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">OpenChat 3.6</h1>
|
| 26 |
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
|
| 27 |
</div>
|
| 28 |
"""
|
|
|
|
| 40 |
background: #1565c0;
|
| 41 |
border-radius: 100vh;
|
| 42 |
}
|
| 43 |
+
|
| 44 |
+
.gradio-container{max-width: 560px !important}
|
| 45 |
+
|
| 46 |
+
footer {
|
| 47 |
+
visibility: hidden
|
| 48 |
+
}
|
| 49 |
"""
|
| 50 |
|
| 51 |
# Load the tokenizer and model
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained("openchat/openchat-3.6-8b-20240522")
|
| 53 |
+
model = AutoModelForCausalLM.from_pretrained("openchat/openchat-3.6-8b-20240522", device_map="auto") # to("cuda:0")
|
| 54 |
terminators = [
|
| 55 |
tokenizer.eos_token_id,
|
| 56 |
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 57 |
]
|
| 58 |
|
| 59 |
@spaces.GPU(duration=120)
|
| 60 |
+
def chat_openchat_36(message: str,
|
| 61 |
history: list,
|
| 62 |
temperature: float,
|
| 63 |
max_new_tokens: int
|
| 64 |
) -> str:
|
| 65 |
"""
|
| 66 |
+
Generate a streaming response using the openchat-3.6 model.
|
| 67 |
Args:
|
| 68 |
message (str): The input message.
|
| 69 |
history (list): The conversation history used by ChatInterface.
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
# Gradio block
|
| 107 |
+
chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, show_label=False)
|
| 108 |
|
| 109 |
with gr.Blocks(fill_height=True, css=css) as demo:
|
| 110 |
|
| 111 |
gr.Markdown(DESCRIPTION)
|
| 112 |
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
| 113 |
gr.ChatInterface(
|
| 114 |
+
fn=chat_openchat_36,
|
| 115 |
chatbot=chatbot,
|
| 116 |
fill_height=True,
|
| 117 |
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|