Upload 2 files
Browse files- app.py +39 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
# Constants
|
5 |
+
TITLE = "Llama2 70B Chatbot"
|
6 |
+
DESCRIPTION = """
|
7 |
+
This Space demonstrates model [Llama-2-70b-chat-hf](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) by Meta,
|
8 |
+
a Llama 2 model with 70B parameters fine-tuned for chat instructions.
|
9 |
+
"""
|
10 |
+
|
11 |
+
# Initialize client
|
12 |
+
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/")
|
13 |
+
|
14 |
+
# Prediction function
|
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
|
19 |
+
temperature, # int | float (numeric value between 0.0 and 1.0)
|
20 |
+
max_new_tokens, # int | float (numeric value between 0 and 4096)
|
21 |
+
0.3, # int | float (numeric value between 0.0 and 1)
|
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 |
+
if st.button("Predict"):
|
37 |
+
response = predict(message, system_prompt, temperature, max_new_tokens)
|
38 |
+
st.write("Response:", response)
|
39 |
+
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio-client==0.0.4
|