Samagra07 commited on
Commit
975588e
·
verified ·
1 Parent(s): 64bff17

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from g4f.client import Client
3
+
4
+ client = Client()
5
+
6
+ def get_response(message, history):
7
+ formatted_history = []
8
+ for user, assistant in history:
9
+ formatted_history.append({"role": "user", "content": user})
10
+ formatted_history.append({"role": "assistant", "content": assistant})
11
+ formatted_history.append({"role": "user", "content": message})
12
+ response = client.chat.completions.create(
13
+ model="gpt-4o",
14
+ messages=formatted_history,
15
+ temperature=0.5
16
+ )
17
+ return response.choices[0].message.content
18
+
19
+ gr.ChatInterface(
20
+ get_response,
21
+ chatbot=gr.Chatbot(height=300),
22
+ textbox=gr.Textbox(placeholder="You can ask anything", container=False, scale=7),
23
+ title="OpenAI GPT-4o",
24
+ retry_btn=None,
25
+ undo_btn="Delete Previous",
26
+ clear_btn="Clear"
27
+ ).launch()
28
+
29
+ gr.ChatInterface(get_response).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ g4f[all]