File size: 1,244 Bytes
fc6227d
 
 
 
5f5d2c7
fc6227d
 
 
e4887c2
fc6227d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import g4f
import gradio as gr


system_msg =  """I want you to act as a machine learning engineer. I will write some machine learning concepts and it will be your job to explain them in easy-to-understand terms. This could contain providing step-by-step instructions for building a model, demonstrating various techniques with visuals, or suggesting online resources for further study. My first suggestion request is 'I have a dataset without labels. Which machine learning algorithm should I use?'"""
# system_msg = """"""
def predict(message, history):
    history_openai_format = []
    history_openai_format.append({"role": "user", "content": system_msg})
    for human, assistant in history:
        history_openai_format.append({"role": "user", "content": human })
        history_openai_format.append({"role": "Bing", "content":assistant})
    history_openai_format.append({"role": "user", "content": message})

    response = g4f.ChatCompletion.create(
    model="gpt-4",
    provider=g4f.Provider.Bing,
    messages=history_openai_format,
    stream=True)

    output = ""
    for message in response:
        output = output + message
        yield output
    response.close()

gr.ChatInterface(predict).queue().launch(share=False)