Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,16 @@
|
|
1 |
import os
|
2 |
from collections.abc import Iterator
|
3 |
from threading import Thread
|
4 |
-
import ai_gradio
|
5 |
import gradio as gr
|
6 |
import spaces
|
7 |
import torch
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
9 |
|
10 |
DESCRIPTION = """
|
11 |
-
# QwQ Tiny
|
12 |
"""
|
13 |
|
14 |
-
css =
|
15 |
h1 {
|
16 |
text-align: center;
|
17 |
display: block;
|
@@ -40,12 +39,6 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
40 |
)
|
41 |
model.eval()
|
42 |
|
43 |
-
# Load Kokoro chatbot
|
44 |
-
kokoro_demo = gr.load(
|
45 |
-
name='onnx-community:kokoro-v1_0',
|
46 |
-
src='ai_gradio.registry',
|
47 |
-
)
|
48 |
-
kokoro_demo.fn = spaces.GPU()(kokoro_demo.fn)
|
49 |
|
50 |
@spaces.GPU
|
51 |
def generate(
|
@@ -57,21 +50,6 @@ def generate(
|
|
57 |
top_k: int = 50,
|
58 |
repetition_penalty: float = 1.2,
|
59 |
) -> Iterator[str]:
|
60 |
-
# Check for tags in the message
|
61 |
-
if "@voice" in message:
|
62 |
-
# Remove the tag from the message
|
63 |
-
message = message.replace("@voice", "").strip()
|
64 |
-
# Use Kokoro for voice
|
65 |
-
yield kokoro_demo.fn(message)
|
66 |
-
elif "@text" in message:
|
67 |
-
# Remove the tag from the message
|
68 |
-
message = message.replace("@text", "").strip()
|
69 |
-
# Fall through to text generation
|
70 |
-
else:
|
71 |
-
# Default to text generation if no tag is specified
|
72 |
-
pass
|
73 |
-
|
74 |
-
# Text generation logic (QwQ Tiny)
|
75 |
conversation = [*chat_history, {"role": "user", "content": message}]
|
76 |
|
77 |
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt")
|
@@ -100,6 +78,7 @@ def generate(
|
|
100 |
outputs.append(text)
|
101 |
yield "".join(outputs)
|
102 |
|
|
|
103 |
demo = gr.ChatInterface(
|
104 |
fn=generate,
|
105 |
additional_inputs=[
|
@@ -145,8 +124,6 @@ demo = gr.ChatInterface(
|
|
145 |
["Write a Python function to check if a number is prime. "],
|
146 |
["What causes rainbows to form?"],
|
147 |
["Rewrite the following sentence in passive voice: 'The dog chased the cat.'"],
|
148 |
-
["@voice Hello, how are you today?"],
|
149 |
-
["@text Explain the theory of relativity."],
|
150 |
],
|
151 |
cache_examples=False,
|
152 |
type="messages",
|
@@ -155,5 +132,6 @@ demo = gr.ChatInterface(
|
|
155 |
fill_height=True,
|
156 |
)
|
157 |
|
|
|
158 |
if __name__ == "__main__":
|
159 |
demo.queue(max_size=20).launch()
|
|
|
1 |
import os
|
2 |
from collections.abc import Iterator
|
3 |
from threading import Thread
|
|
|
4 |
import gradio as gr
|
5 |
import spaces
|
6 |
import torch
|
7 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
8 |
|
9 |
DESCRIPTION = """
|
10 |
+
# QwQ Tiny
|
11 |
"""
|
12 |
|
13 |
+
css ='''
|
14 |
h1 {
|
15 |
text-align: center;
|
16 |
display: block;
|
|
|
39 |
)
|
40 |
model.eval()
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
@spaces.GPU
|
44 |
def generate(
|
|
|
50 |
top_k: int = 50,
|
51 |
repetition_penalty: float = 1.2,
|
52 |
) -> Iterator[str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
conversation = [*chat_history, {"role": "user", "content": message}]
|
54 |
|
55 |
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt")
|
|
|
78 |
outputs.append(text)
|
79 |
yield "".join(outputs)
|
80 |
|
81 |
+
|
82 |
demo = gr.ChatInterface(
|
83 |
fn=generate,
|
84 |
additional_inputs=[
|
|
|
124 |
["Write a Python function to check if a number is prime. "],
|
125 |
["What causes rainbows to form?"],
|
126 |
["Rewrite the following sentence in passive voice: 'The dog chased the cat.'"],
|
|
|
|
|
127 |
],
|
128 |
cache_examples=False,
|
129 |
type="messages",
|
|
|
132 |
fill_height=True,
|
133 |
)
|
134 |
|
135 |
+
|
136 |
if __name__ == "__main__":
|
137 |
demo.queue(max_size=20).launch()
|