Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,7 @@ import os, json
|
|
| 9 |
from sys import argv
|
| 10 |
from vllm import LLM, SamplingParams
|
| 11 |
import vllm
|
| 12 |
-
|
| 13 |
-
from huggingface_hub import login
|
| 14 |
-
TOKEN = os.environ.get("TOKEN", None)
|
| 15 |
-
login(token=TOKEN)
|
| 16 |
-
|
| 17 |
-
print("transformers version:", transformers.__version__)
|
| 18 |
-
print("vllm version:", vllm.__version__)
|
| 19 |
-
print("gradio version:", gr.__version__)
|
| 20 |
|
| 21 |
|
| 22 |
def load_model_processor(model_path):
|
|
@@ -31,7 +24,7 @@ def load_model_processor(model_path):
|
|
| 31 |
model_path1 = "SeaLLMs/SeaLLMs-Audio-7B"
|
| 32 |
model1, processor1 = load_model_processor(model_path1)
|
| 33 |
|
| 34 |
-
def response_to_audio(audio_url, text, model=None, processor=None, temperature = 0
|
| 35 |
if text == None:
|
| 36 |
conversation = [
|
| 37 |
{"role": "user", "content": [
|
|
@@ -80,29 +73,55 @@ def response_to_audio(audio_url, text, model=None, processor=None, temperature =
|
|
| 80 |
def clear_inputs():
|
| 81 |
return None, "", ""
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
def compare_responses(audio_url, text):
|
|
|
|
|
|
|
|
|
|
| 84 |
response1 = response_to_audio(audio_url, text, model1, processor1)
|
|
|
|
|
|
|
|
|
|
| 85 |
return response1
|
| 86 |
|
| 87 |
with gr.Blocks() as demo:
|
| 88 |
# gr.Markdown(f"Evaluate {model_path1}")
|
| 89 |
-
|
| 90 |
# gr.Image("images/seal_logo.png", elem_id="seal_logo", show_label=False,height=80,show_fullscreen_button=False)
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
)
|
| 107 |
|
| 108 |
# gr.Markdown(insturctions)
|
|
|
|
| 9 |
from sys import argv
|
| 10 |
from vllm import LLM, SamplingParams
|
| 11 |
import vllm
|
| 12 |
+
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def load_model_processor(model_path):
|
|
|
|
| 24 |
model_path1 = "SeaLLMs/SeaLLMs-Audio-7B"
|
| 25 |
model1, processor1 = load_model_processor(model_path1)
|
| 26 |
|
| 27 |
+
def response_to_audio(audio_url, text, model=None, processor=None, temperature = 0,repetition_penalty=1.1, top_p = 0.9,max_new_tokens = 2048):
|
| 28 |
if text == None:
|
| 29 |
conversation = [
|
| 30 |
{"role": "user", "content": [
|
|
|
|
| 73 |
def clear_inputs():
|
| 74 |
return None, "", ""
|
| 75 |
|
| 76 |
+
def contains_chinese(text):
|
| 77 |
+
# Regular expression for Chinese characters
|
| 78 |
+
chinese_char_pattern = re.compile(r'[\u4e00-\u9fff]')
|
| 79 |
+
return bool(chinese_char_pattern.search(text))
|
| 80 |
+
|
| 81 |
def compare_responses(audio_url, text):
|
| 82 |
+
if contains_chinese(text):
|
| 83 |
+
return "Caution! This demo does not support Chinese!"
|
| 84 |
+
|
| 85 |
response1 = response_to_audio(audio_url, text, model1, processor1)
|
| 86 |
+
if contains_chinese(response1):
|
| 87 |
+
return "ERROR! Try another example!"
|
| 88 |
+
|
| 89 |
return response1
|
| 90 |
|
| 91 |
with gr.Blocks() as demo:
|
| 92 |
# gr.Markdown(f"Evaluate {model_path1}")
|
| 93 |
+
gr.HTML("""<p align="center"><img src="https://DAMO-NLP-SG.github.io/SeaLLMs-Audio/static/images/seallm-audio-logo.png" style="height: 80px"/><p>""")
|
| 94 |
# gr.Image("images/seal_logo.png", elem_id="seal_logo", show_label=False,height=80,show_fullscreen_button=False)
|
| 95 |
+
gr.HTML("""<h1 align="center" id="space-title">SeaLLMs-Audio-Demo</h1>""")
|
| 96 |
+
# gr.Markdown(
|
| 97 |
+
# """\
|
| 98 |
+
# <center><font size=4>This WebUI is based on SeaLLMs-Audio-7B, developed by Alibaba DAMO Academy.<br>
|
| 99 |
+
# You can interact with the chatbot in <b>English, Chinese, Indonesian, Thai, or Vietnamese</b>.<br>
|
| 100 |
+
# For the input, you can input <b>audio and/or text</center>.""")
|
| 101 |
+
|
| 102 |
+
# # Links with proper formatting
|
| 103 |
+
# gr.Markdown(
|
| 104 |
+
# """<center><font size=4>
|
| 105 |
+
# <a href="https://huggingface.co/SeaLLMs/SeaLLMs-v3-7B-Chat">[Website]</a>
|
| 106 |
+
# <a href="https://huggingface.co/SeaLLMs/SeaLLMs-Audio-7B">[Model🤗]</a>
|
| 107 |
+
# <a href="https://github.com/DAMO-NLP-SG/SeaLLMs-Audio">[Github]</a>
|
| 108 |
+
# </center>""",
|
| 109 |
+
# )
|
| 110 |
+
|
| 111 |
+
gr.HTML(
|
| 112 |
+
"""<div style="text-align: center; font-size: 16px;">
|
| 113 |
+
This WebUI is based on <a href="https://huggingface.co/SeaLLMs/SeaLLMs-Audio-7B">SeaLLMs-Audio-7B</a>, developed by Alibaba DAMO Academy.<br>
|
| 114 |
+
You can interact with the chatbot in <b>English, Indonesian, Thai, or Vietnamese</b>.<br>
|
| 115 |
+
For the input, you can provide <b>audio and/or text</b>.
|
| 116 |
+
</div>"""
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
gr.HTML(
|
| 120 |
+
"""<div style="text-align: center; font-size: 16px;">
|
| 121 |
+
<a href="https://DAMO-NLP-SG.github.io/SeaLLMs-Audio/">[Website]</a>
|
| 122 |
+
<a href="https://huggingface.co/SeaLLMs/SeaLLMs-Audio-7B">[Model🤗]</a>
|
| 123 |
+
<a href="https://github.com/DAMO-NLP-SG/SeaLLMs-Audio">[Github]</a>
|
| 124 |
+
</div>"""
|
| 125 |
)
|
| 126 |
|
| 127 |
# gr.Markdown(insturctions)
|