Team Ai
Apppublic

haystack777/haystack

sourceHugging Faceunknownupdated 2y agoView on Hugging Face
0likes
chatbot26 linesDownload Raw Back to root
1!pip install OpenAI2!pip install gradio3import gradio as gr4import openai5openai.api_key = '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'6def ask_openai(question):7    try:8        response = openai.chat.completions.create(9            model="gpt-3.5-turbo",10            messages=[11                {"role": "system", "content": "You are a helpful assistant."},12                {"role": "user", "content": question},13            ],14        )15        return response['choices'][0]['message']['content'].strip()16    except Exception as e:17        return f"حدث خطأ: {str(e)}"18iface = gr.Interface(19    fn=ask_openai,20    inputs=gr.Textbox(label="أدخل سؤالك"),21    outputs=gr.Textbox(label="الإجابة"),22    live=True,23    title="شات بوت الذكاء الاصطناعي",24    description="اكتب أي سؤال وسأجيبك باستخدام GPT-3.5 Turbo من OpenAI."25)26iface.launch()