ChatGPT_HF / app.py
akhaliq's picture
akhaliq HF staff
add duplicate badge
baaff39
raw
history blame
5.38 kB
# !pip install
from pyChatGPT import ChatGPT
import os
# refresh the authorization token
def chat_hf(text,session_tokenz):
try:
# Save the session_token variable to the system environment
# os.environ['SESSION_TOKEN'] = session_token
# Load the saved session_token value from the system environment
loaded_session_token = os.environ['Sessionkeyz']
session_token='eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..mSU2Bih8U-Gbwl-L.SVQvNyNTsGMEVeyO1SNCKrivpBEgzB_8dEo-frhTGyQFrgk7nBr4gqjYjpxniZX0U3uEWunn_74YAtEUzzbShA55zRDWbElQVoMeTQs2_bM_fVqIEbg6UNuqDtkrMhPr3J3tij4IJSn9Eg2wy0zEWFBbN4wYHmyGPWpc24PClgH8WcwNV00QvkblmAw8X1L-D8uwmOhqXLhasr0kbCqgTm1jW60dTlGslRWMK7G4cVbnbEuwMnNXhKWx3MY5-Jbn4Ssi3CvSb8PsJevbWB3iLsdEhP5SUXiIsFU2szAWH-fTeRte5D1obZVF8sI5VWNTNbROln-w1fNW3kJ7XGyTUtQJ4Tqxk9Yd6r6bjZIuTIUfSwhcSwYtWjzRJaTgvRYjzi5CpMwVgNQgZ-VKLzTKqyb0ZXYv2iMwNwW3vDsy7XESHCVxbKF5xzIvo_pa_UIUazziN8fBeI2T7dR2PIdaP5fnjWX4G4cq5VFrkDwYUBhaBNf0b499Pk0Wvd_3425O_WsO6TrzOUGFyQWBrZOTTti9vmZe6dJ-imV_CVzRnXXBgSbNu9SvUvFX07872EYnDl55i48xydtKyiducabjtC-WG_8nJX312ltPV7KLUEruV943B6oj1QH0s_YACO9IxWZ5PcxDrK4UBxT_5VaAIjuosck2U9-jCt8a5lQoAfrvB7nhFTiMvh0_cB7ZTqDAxRTAvaC3yD-YyUQWLwWLSm8VoCPbVlPabX4f8MnrWzWtWJDgrPM9ABbzhkX_DM202DoTglN3Irvs1ozMijstobXP9OUlm_pduXEpcAm5jjrAm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T4RH9MHtbkqAK41D_yJH_tYhRZZwU9sygHblkY34g1X95XBZVB2nL0o1IeNRZ5CWclfKKfr9o2cRQqj9HyD7PD48paxoGNc3bZ5xWgjqv_1-ixUtwKWBgArY7S1DQwKMHLmdaycOPlSPqxv5diyjvjxYHtThXibh58mxdvwWKreV99TI23NXl4EaynaziZST21Tg-SwOJz_x30T1wAOi5p54SpX4rBDamZXhzVmvT4Qxjd-61VSzJIq5WB5eoIIsZIl66N-Q-bXm1_TflDiiY97JCxlmQAjeABGB8PQh05YozcVlJZXwulYM-U-JUQzOZOfERheXTteQMbx-S5AofwA9ZHgw4DgOBbUMYJS-BWqiYBzdej2gxjxdoj8ul0Gpo4shThPf-A7-YQqFHdd87MYD3Zg2W21t5CDPrNzMWEjOp-n5Dgfum8zv5bj0j-EtAIfRqg66Ch58ny9sECCZvluBrYaop4XjfH4q_.fdtq7gNDgruu5U_ww28O0g'
api = ChatGPT(session_token)
# api = ChatGPT(loaded_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")
, 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)
<p>You can duplicating this space and use your own session token: <a style='display:inline-block' href='https://huggingface.co/spaces/Xhaheen/ChatGPT_HF?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14' alt='Duplicate Space'></a></p>
""").launch(debug = True)