Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,31 @@
|
|
1 |
-
|
2 |
-
|
3 |
# Import required libraries
|
4 |
import gradio as gr
|
5 |
-
from huggingface_hub import InferenceClient
|
6 |
from transformers import pipeline
|
7 |
import torch
|
8 |
-
import huggingfacehub as infer
|
9 |
import threading
|
10 |
import time
|
11 |
import tensorflow as tf
|
12 |
-
from transformers import pipeline
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
|
19 |
# Initialize the text generation pipeline with the specified model
|
20 |
-
pipe = pipeline("text-generation", model="chargoddard/Yi-34B-Llama"
|
21 |
|
22 |
def respond(
|
23 |
message,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
response = ""
|
26 |
|
@@ -33,19 +38,25 @@ def respond(
|
|
33 |
top_p=top_p,
|
34 |
)
|
35 |
|
36 |
-
|
37 |
response = result[0]['generated_text']
|
38 |
-
yield response
|
39 |
|
40 |
# Gradio interface setup
|
41 |
-
|
42 |
-
|
43 |
demo = gr.ChatInterface(
|
44 |
respond,
|
45 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
],
|
47 |
)
|
48 |
|
49 |
-
|
50 |
if __name__ == "__main__":
|
51 |
demo.launch()
|
|
|
|
|
|
|
1 |
# Import required libraries
|
2 |
import gradio as gr
|
|
|
3 |
from transformers import pipeline
|
4 |
import torch
|
|
|
5 |
import threading
|
6 |
import time
|
7 |
import tensorflow as tf
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Initialize the text generation pipeline with the specified model
|
10 |
+
pipe = pipeline("text-generation", model="chargoddard/Yi-34B-Llama")
|
11 |
|
12 |
def respond(
|
13 |
message,
|
14 |
+
history: list[tuple[str, str]],
|
15 |
+
system_message,
|
16 |
+
max_tokens,
|
17 |
+
temperature,
|
18 |
+
top_p,
|
19 |
+
):
|
20 |
+
messages = [{"role": "system", "content": system_message}]
|
21 |
+
|
22 |
+
for val in history:
|
23 |
+
if val[0]:
|
24 |
+
messages.append({"role": "user", "content": val[0]})
|
25 |
+
if val[1]:
|
26 |
+
messages.append({"role": "assistant", "content": val[1]})
|
27 |
+
|
28 |
+
messages.append({"role": "user", "content": message})
|
29 |
|
30 |
response = ""
|
31 |
|
|
|
38 |
top_p=top_p,
|
39 |
)
|
40 |
|
|
|
41 |
response = result[0]['generated_text']
|
42 |
+
yield response
|
43 |
|
44 |
# Gradio interface setup
|
|
|
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
49 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
50 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
+
gr.Slider(
|
52 |
+
minimum=0.1,
|
53 |
+
maximum=1.0,
|
54 |
+
value=0.95,
|
55 |
+
step=0.05,
|
56 |
+
label="Top-p (nucleus sampling)",
|
57 |
+
),
|
58 |
],
|
59 |
)
|
60 |
|
|
|
61 |
if __name__ == "__main__":
|
62 |
demo.launch()
|