Samagra07 commited on
Commit
47477d2
·
verified ·
1 Parent(s): 6a1dce2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from g4f.client import Client
3
+
4
+ client = Client()
5
+ st.title("GPT-4o-Mini")
6
+
7
+ if "messages" not in st.session_state:
8
+ st.session_state.messages = []
9
+
10
+ for message in st.session_state['messages']:
11
+ with st.chat_message(message['role']):
12
+ st.markdown(message['content'])
13
+
14
+ if prompt := st.chat_input("Enter a prompt"):
15
+ st.session_state.messages.append({"role": "user", "content": prompt})
16
+ with st.chat_message("user"):
17
+ st.markdown(prompt)
18
+
19
+ with st.chat_message("assistant"):
20
+ chatbot_msg = st.empty()
21
+ full_response = ""
22
+ stream = client.chat.completions.create(
23
+ model="gpt-4o-mini",
24
+ messages=[
25
+ {"role": msg["role"], "content": msg["content"]}
26
+ for msg in st.session_state['messages']
27
+ ],
28
+ stream=True
29
+ )
30
+ for chunk in stream:
31
+ token = chunk.choices[0].delta.content
32
+ if token is not None:
33
+ full_response += token
34
+ chatbot_msg.markdown(full_response)
35
+ chatbot_msg.markdown(full_response)
36
+ st.session_state.messages.append({"role": "assistant", "content": full_response})
37
+
38
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ g4f[all]