Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,26 @@
|
|
1 |
-
import
|
2 |
from gradio_client import Client
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
# Initialize client
|
12 |
-
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/")
|
13 |
|
14 |
-
#
|
15 |
-
def predict(message, system_prompt="", temperature=0.9, max_new_tokens=4096):
|
16 |
return client.predict(
|
17 |
message, # str in 'Message' Textbox component
|
18 |
system_prompt, # str in 'Optional system prompt' Textbox component
|
@@ -22,18 +30,35 @@ def predict(message, system_prompt="", temperature=0.9, max_new_tokens=4096):
|
|
22 |
1, # int | float (numeric value between 1.0 and 2.0)
|
23 |
api_name="/chat"
|
24 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
# Streamlit UI
|
27 |
-
st.title(TITLE)
|
28 |
-
st.write(DESCRIPTION)
|
29 |
|
30 |
-
# Input fields
|
31 |
-
message = st.text_area("Enter your message:", "")
|
32 |
-
system_prompt = st.text_area("Optional system prompt:", "")
|
33 |
-
temperature = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.9, step=0.05)
|
34 |
-
max_new_tokens = st.slider("Max new tokens", min_value=0, max_value=4096, value=4096, step=64)
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
st.write("Response:", response)
|
39 |
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
|
4 |
+
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/")
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
title = "Llama2 70B Chatbot"
|
9 |
+
description = """
|
10 |
+
This Space demonstrates model [Llama-2-70b-chat-hf](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) by Meta, a Llama 2 model with 70B parameters fine-tuned for chat instructions.
|
11 |
"""
|
12 |
+
css = """.toast-wrap { display: none !important } """
|
13 |
+
examples=[
|
14 |
+
['Hello there! How are you doing?'],
|
15 |
+
['Can you explain to me briefly what is Python programming language?'],
|
16 |
+
['Explain the plot of Cinderella in a sentence.'],
|
17 |
+
['How many hours does it take a man to eat a Helicopter?'],
|
18 |
+
["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
|
19 |
+
]
|
20 |
|
|
|
|
|
21 |
|
22 |
+
# Stream text
|
23 |
+
def predict(message, chatbot, system_prompt="", temperature=0.9, max_new_tokens=4096):
|
24 |
return client.predict(
|
25 |
message, # str in 'Message' Textbox component
|
26 |
system_prompt, # str in 'Optional system prompt' Textbox component
|
|
|
30 |
1, # int | float (numeric value between 1.0 and 2.0)
|
31 |
api_name="/chat"
|
32 |
)
|
33 |
+
|
34 |
+
|
35 |
+
additional_inputs=[
|
36 |
+
gr.Textbox("", label="Optional system prompt"),
|
37 |
+
gr.Slider(
|
38 |
+
label="Temperature",
|
39 |
+
value=0.9,
|
40 |
+
minimum=0.0,
|
41 |
+
maximum=1.0,
|
42 |
+
step=0.05,
|
43 |
+
interactive=True,
|
44 |
+
info="Higher values produce more diverse outputs",
|
45 |
+
),
|
46 |
+
gr.Slider(
|
47 |
+
label="Max new tokens",
|
48 |
+
value=4096,
|
49 |
+
minimum=0,
|
50 |
+
maximum=4096,
|
51 |
+
step=64,
|
52 |
+
interactive=True,
|
53 |
+
info="The maximum numbers of new tokens",
|
54 |
+
)
|
55 |
+
]
|
56 |
|
|
|
|
|
|
|
57 |
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
# Gradio Demo
|
60 |
+
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
|
|
61 |
|
62 |
+
gr.ChatInterface(predict, title=title, description=description, css=css, examples=examples, additional_inputs=additional_inputs)
|
63 |
+
|
64 |
+
demo.queue().launch(debug=True)
|