|
import gradio as gr |
|
from g4f.client import Client |
|
|
|
|
|
client = Client() |
|
|
|
|
|
def chat_with_gpt(user_input): |
|
try: |
|
response = client.chat.completions.create( |
|
model="gpt-4o", |
|
messages=[{"role": "user", "content": user_input}] |
|
) |
|
return response.choices[0].message.content |
|
except Exception as e: |
|
return str(e) |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Chat with GPT-4o") |
|
|
|
user_input = gr.Textbox(label="You:", placeholder="Type your message here...") |
|
output = gr.Textbox(label="GPT-4o:", interactive=False) |
|
|
|
submit_button = gr.Button("Send") |
|
|
|
submit_button.click(chat_with_gpt, inputs=user_input, outputs=output) |
|
|
|
|
|
demo.launch() |
|
|