Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Define the API endpoint and headers
|
| 5 |
+
url = "https://api.together.xyz/inference"
|
| 6 |
+
headers = {
|
| 7 |
+
"accept": "application/json",
|
| 8 |
+
"content-type": "application/json",
|
| 9 |
+
"Authorization": "Bearer cad84f39be62a8e36fdd846152dbb18abddef0aefcd921e82e287b4c228ac3e1"
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
# Define the Streamlit app
|
| 13 |
+
def main():
|
| 14 |
+
st.title("Streamlit Chatbot")
|
| 15 |
+
|
| 16 |
+
# Create a text input for the user to type their message
|
| 17 |
+
user_input = st.text_input("You: ", key="input")
|
| 18 |
+
|
| 19 |
+
# If the user has entered a message
|
| 20 |
+
if user_input:
|
| 21 |
+
# Create the payload for the API request
|
| 22 |
+
payload = {
|
| 23 |
+
"model": "togethercomputer/CodeLlama-34b-Instruct",
|
| 24 |
+
"prompt": user_input,
|
| 25 |
+
"max_tokens": 512,
|
| 26 |
+
"stop": ".",
|
| 27 |
+
"temperature": 0.1,
|
| 28 |
+
"top_p": 0.7,
|
| 29 |
+
"top_k": 50,
|
| 30 |
+
"repetition_penalty": 1
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
# Send the API request
|
| 34 |
+
response = requests.post(url, json=payload, headers=headers)
|
| 35 |
+
|
| 36 |
+
# Display the response from the API
|
| 37 |
+
st.write(f"Bot: {response.json()['text']}")
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
main()
|