Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,36 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
st.success('Classification complete!')
|
38 |
-
st.write("Prediction:", results)
|
39 |
-
|
40 |
-
if __name__ == '__main__':
|
41 |
-
main()
|
42 |
-
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import requests
|
4 |
+
|
5 |
+
# Initialize the tokenizer and model
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("PawanKrd/CosmosRP-8k")
|
7 |
+
model = AutoModelForCausalLM.from_pretrained("PawanKrd/CosmosRP-8k")
|
8 |
+
|
9 |
+
st.title("CosmosRP-8k Roleplay Chatbot")
|
10 |
+
|
11 |
+
user_input = st.text_input("You:", "")
|
12 |
+
|
13 |
+
if st.button("Generate Response"):
|
14 |
+
if user_input:
|
15 |
+
# Define the endpoint and payload
|
16 |
+
endpoint_url = "https://api.pawan.krd/cosmosrp/v1/chat/completions"
|
17 |
+
headers = {
|
18 |
+
"Content-Type": "application/json"
|
19 |
+
}
|
20 |
+
data = {
|
21 |
+
"model": "cosmosrp",
|
22 |
+
"messages": [
|
23 |
+
{"role": "system", "content": "You are a roleplay assistant."},
|
24 |
+
{"role": "user", "content": user_input}
|
25 |
+
]
|
26 |
+
}
|
27 |
+
|
28 |
+
# Make the request to the API
|
29 |
+
response = requests.post(endpoint_url, headers=headers, json=data)
|
30 |
+
result = response.json()
|
31 |
+
|
32 |
+
# Extract and display the response
|
33 |
+
generated_response = result['choices'][0]['message']['content']
|
34 |
+
st.text_area("CosmosRP-8k:", generated_response)
|
35 |
+
else:
|
36 |
+
st.warning("Please enter some text.")
|
|
|
|
|
|
|
|
|
|
|
|