File size: 2,243 Bytes
d2704de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# !pip install 


from pyChatGPT import ChatGPT
import os




 

  # 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['SESSION_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['SESSION_TOKEN']

      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   for ChatGPT'),
               gr.Textbox(label = ' If it fails enter cusom session ')], 
                        outputs = gr.outputs.Textbox(type="text",label="chatGPT response")
                        , title = "" +' ChatGpt πŸ€–πŸ’¬πŸ’» on hugginface. '+ "",
                                    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)").launch(share = True, debug = True)