File size: 907 Bytes
975588e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
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
import gradio as gr
from g4f.client import Client

client = Client()

def get_response(message, history):
    formatted_history = []
    for user, assistant in history:
        formatted_history.append({"role": "user", "content": user})
        formatted_history.append({"role": "assistant", "content": assistant})
    formatted_history.append({"role": "user", "content": message})
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=formatted_history,
        temperature=0.5
    )
    return response.choices[0].message.content

gr.ChatInterface(
    get_response,
    chatbot=gr.Chatbot(height=300),
    textbox=gr.Textbox(placeholder="You can ask anything", container=False, scale=7),
    title="OpenAI GPT-4o",
    retry_btn=None,
    undo_btn="Delete Previous",
    clear_btn="Clear"
).launch()

gr.ChatInterface(get_response).launch()