File size: 1,402 Bytes
a102655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@file  : app.py
@author: sunzijun
@contact : [email protected]
@date  : 2022/12/7 1:08 上午
@version: 1.0
@desc  : 
"""
import os

from pyChatGPT import ChatGPT


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 '),
     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 powerful dialog model trained by OpenAI").launch(
    debug=True)