Spaces:
Build error
Build error
Update app.py
Browse files7 unmodified lines891011121314336 unmodified lines35135235335435535635735835936061 unmodified lines42242342442542642742851 unmodified lines48048148248348448548648714 unmodified lines5025035045055065075085095105115125135145155167 unmodified linesimport randomfrom encoder import get_encoderopenai.api_key = os.getenv("OPENAI_API_KEY")from utils import get_tmt_client, getTextTrans_tmttmt_client = get_tmt_client()336 unmodified linesmax_output_tokens = 1024max_input_tokens = total_tokens - max_output_tokensdef set_openai_api_key(api_key):if api_key and api_key.startswith("sk-") and len(api_key) > 50:openai.api_key = api_keydef get_response_from_openai(input, chat_history, model_radio):error_1 = 'You exceeded your current quota, please check your plan and billing details.'def openai_create(input_list, model_radio):61 unmodified linesreturn ret, response.usageexcept Exception as e:logger.info(f"openai_create_error__{e}")ret = f"Openai said: {e} Perhaps enter your OpenAI API key."return ret, {"completion_tokens": -1, "prompt_tokens": -1, "total_tokens": -1}# logger.info(f'chat_history = {chat_history}')51 unmodified lineschat_radio = gr.Radio(["Talk to chatGPT", "Text to Image"], elem_id="chat_radio",value="Talk to chatGPT", show_label=False, visible=True)model_radio = gr.Radio(["GPT-3.0", "GPT-3.5"], elem_id="model_radio", value="GPT-3.5",label='GPT model: ', show_label=True,interactive=True, visible=True)openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...) and hit Enter",show_label=False, lines=1, type='password')with gr.Row(elem_id="btns_row"):with gr.Column(id="submit_col"):submit_btn = gr.Button(value = "submit",elem_id="submit-btn").style(14 unmodified lineswith gr.Row(elem_id='tab_img', visible=False).style(height=5):tab_img = gr.TabbedInterface(tab_actions, tab_titles)openai_api_key_textbox.change(set_openai_api_key,inputs=[openai_api_key_textbox],outputs=[])openai_api_key_textbox.submit(set_openai_api_key,inputs=[openai_api_key_textbox],outputs=[])chat_radio.change(fn=chat_radio_change,inputs=[chat_radio],outputs=[model_radio, openai_api_key_textbox],)demo.launch(debug = True)7 unmodified lines891011121314336 unmodified lines35135235335435535661 unmodified lines41841942042142242351 unmodified lines47547647747847948014 unmodified lines4954964974984995007 unmodified linesimport randomfrom encoder import get_encoderopenai.api_key = sk-oIyK22lx6cgKGDc8Piq0T3BlbkFJVrJoREIf2bQtCvIYK9N5from utils import get_tmt_client, getTextTrans_tmttmt_client = get_tmt_client()336 unmodified linesmax_output_tokens = 1024max_input_tokens = total_tokens - max_output_tokensdef get_response_from_openai(input, chat_history, model_radio):error_1 = 'You exceeded your current quota, please check your plan and billing details.'def openai_create(input_list, model_radio):61 unmodified linesreturn ret, response.usageexcept Exception as e:logger.info(f"openai_create_error__{e}")return ret, {"completion_tokens": -1, "prompt_tokens": -1, "total_tokens": -1}# logger.info(f'chat_history = {chat_history}')51 unmodified lineschat_radio = gr.Radio(["Talk to chatGPT", "Text to Image"], elem_id="chat_radio",value="Talk to chatGPT", show_label=False, visible=True)model_radio = gr.Radio(["GPT-3.0", "GPT-3.5"], elem_id="model_radio", value="GPT-3.5",label='GPT model: ', show_label=True,interactive=True, visible=True)with gr.Row(elem_id="btns_row"):with gr.Column(id="submit_col"):submit_btn = gr.Button(value = "submit",elem_id="submit-btn").style(14 unmodified lineswith gr.Row(elem_id='tab_img', visible=False).style(height=5):tab_img = gr.TabbedInterface(tab_actions, tab_titles)demo.launch(debug = True)
app.py+2-18