Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the recent change in Gradio's API #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Madusalves
Copy link

1. Removed gr.inputs and gr.outputs.
2. Directly pass the Gradio input and output components to the Interface function.
3. Updated the import statement to import gradio as gr (assuming you have Gradio installed).

import openai
import gradio as gr

openai.api_key = "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"

messages = [
    {"role": "system", "content": "You are a helpful and kind AI Assistant."},
]


def chatbot(input):
    if input:
        messages.append({"role": "user", "content": input})
        chat = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", messages=messages
        )
        reply = chat.choices[0].message.content
        messages.append({"role": "assistant", "content": reply})
        return reply


interface = gr.Interface(
    fn=chatbot,
    inputs=gr.Textbox(lines=7, label="Chat with AI"),
    outputs=gr.Textbox(label="Reply"),
    title="ChatGPT : Meow!",
    description="Ask anything you want",
    theme="compact",
)

interface.launch(share=True)

@Madusalves Madusalves changed the title Fixinh the recent change in Gradio's API Fixing the recent change in Gradio's API May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant