from pyChatGPT import ChatGPT import os # os.environ["SessionToken"] = SessionToken # refresh the authorization token session_token = os.environ.get('SessionToken') def chat_hf(text,session_tokenz): try: api = ChatGPT(session_token) resp = api.send_message(text) api.refresh_auth() # refresh the authorization token api.reset_conversation() # reset the conversation xyz = resp['message'] except: api = ChatGPT(session_tokenz) resp = api.send_message(text) api.refresh_auth() # refresh the authorization token api.reset_conversation() # reset the conversation xyz = resp['message'] return xyz #@title GRadio for SDK api import gradio as gr gr.Interface( chat_hf, [gr.Textbox(label = ' Input custom text for ChatGPT! '), gr.Textbox(label = ' If it fails enter custom session key ')], outputs = gr.outputs.Textbox(type="text",label="chatGPT response"), examples =[['Write poem on crypto','xyz'],['Write a sales pitch for social media app','xyz'],['Reverse string in python','xyz'] ] , title = "" +' ChatGpt 🤖💬💻 on 🤗 huggingface. '+ "", description="""ChatGPT 🤖💬💻 is a conversational AI app that allows users to engage in natural language conversations with a virtual assistant. The app uses advanced machine learning algorithms to understand and respond to user queries in a human-like manner. With its ability to answer follow-up questions, admit mistakes, and reject inappropriate requests, ChatGPT offers a highly interactive and engaging experience. Try ChatGPT now and experience the power of language modeling in dialogue built with ❤️ @[Xhaheen](https://www.linkedin.com/in/sallu-mandya/) \n\nIf it fails enter cusom session key see video for reference refer @[Bhavesh bhat video](https://youtu.be/TdNSj_qgdFk)

You can duplicating this space and use your own session token: Duplicate Space

""").launch(debug = True)