slimshadow commited on
Commit
8839c6c
·
verified ·
1 Parent(s): 0f4a91f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import json
4
+
5
+ # Function to call the API
6
+ def call_chatgpt_api(message):
7
+ url = "https://api.safone.dev/chatgpt"
8
+ headers = {
9
+ "accept": "application/json",
10
+ "Content-Type": "application/json"
11
+ }
12
+ payload = {
13
+ "message": message,
14
+ "version": 3,
15
+ "chat_mode": "assistant",
16
+ "dialog_messages": "[{\"bot\":\"\",\"user\":\"\"}]"
17
+ }
18
+
19
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
20
+ if response.status_code == 200:
21
+ return response.json()
22
+ else:
23
+ return None
24
+
25
+ # Streamlit App
26
+ st.title('SlimshadowGPT')
27
+ st.write("This is a simple interface to interact with the GPT-3.5 API.")
28
+
29
+ user_input = st.text_input("Enter your message:")
30
+
31
+ if st.button('Send'):
32
+ if user_input:
33
+ with st.spinner('Generating response...'):
34
+ response = call_chatgpt_api(user_input)
35
+ if response:
36
+ st.write("Assistant:", response['choices'][0]['message']['content'])
37
+ else:
38
+ st.write("Failed to get a response from the API.")
39
+ else:
40
+ st.write("Please enter a message to send.")
41
+
42
+ # Run the app using `streamlit run app.py` in the terminal