Illia56 commited on
Commit
86b946a
1 Parent(s): 7828943

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=message,
18
+ system_prompt=system_prompt,
19
+ temperature=temperature,
20
+ max_new_tokens=max_new_tokens,
21
+ api_name="/chat"
22
+ )
23
+
24
+ # Streamlit UI
25
+ st.title(TITLE)
26
+ st.write(DESCRIPTION)
27
+
28
+ # Input fields
29
+ message = st.text_area("Enter your message:", "")
30
+ system_prompt = st.text_area("Optional system prompt:", "")
31
+ temperature = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.9, step=0.05)
32
+ max_new_tokens = st.slider("Max new tokens", min_value=0, max_value=4096, value=4096, step=64)
33
+
34
+ if st.button("Predict"):
35
+ response = predict(message, system_prompt, temperature, max_new_tokens)
36
+ st.write("Response:", response)
37
+