Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	
		zwq2018
		
	commited on
		
		
					Commit 
							
							·
						
						6fd2be1
	
1
								Parent(s):
							
							80d6583
								
Add application file
Browse files
    	
        app.py
    CHANGED
    
    | @@ -47,6 +47,8 @@ class Client: | |
| 47 | 
             
                def run(self, messages):
         | 
| 48 | 
             
                    if self.OPENAI_KEY == '' and self.OPENAI_API_KEY_AZURE == '':
         | 
| 49 | 
             
                        yield '', np.zeros((100, 100, 3), dtype=np.uint8), "Please set your OpenAI API key first!!!", pd.DataFrame()
         | 
|  | |
|  | |
| 50 | 
             
                    else:
         | 
| 51 | 
             
                        # self.stop = False
         | 
| 52 | 
             
                        gen = gradio_interface(messages, self.OPENAI_KEY, self.OPENAI_API_KEY_AZURE, self.OPENAI_API_BASED_AZURE, self.OPENAI_ENGINE_AZURE)
         | 
| @@ -83,6 +85,10 @@ with gr.Blocks() as demo: | |
| 83 | 
             
                if not OPENAI_KEY:
         | 
| 84 | 
             
                    with gr.Row().style():
         | 
| 85 | 
             
                        with gr.Column(scale=0.95):
         | 
|  | |
|  | |
|  | |
|  | |
| 86 | 
             
                            openai_api_key = gr.Textbox(
         | 
| 87 | 
             
                                show_label=False,
         | 
| 88 | 
             
                                placeholder="Set your OpenAI API key here and press Submit  (e.g. sk-xxx)",
         | 
| @@ -93,22 +99,20 @@ with gr.Blocks() as demo: | |
| 93 | 
             
                            with gr.Row():
         | 
| 94 | 
             
                                openai_api_key_azure = gr.Textbox(
         | 
| 95 | 
             
                                    show_label=False,
         | 
| 96 | 
            -
                                    placeholder="Set your Azure-OpenAI key | 
| 97 | 
             
                                    lines=1,
         | 
| 98 | 
             
                                    type="password"
         | 
| 99 | 
             
                                ).style(container=False)
         | 
| 100 | 
             
                                openai_api_base_azure = gr.Textbox(
         | 
| 101 | 
             
                                    show_label=False,
         | 
| 102 | 
            -
                                    placeholder=" | 
| 103 | 
            -
             | 
| 104 | 
            -
                                    lines=2,
         | 
| 105 | 
             
                                    type="password"
         | 
| 106 | 
             
                                ).style(container=False)
         | 
| 107 | 
             
                                openai_api_engine_azure = gr.Textbox(
         | 
| 108 | 
             
                                    show_label=False,
         | 
| 109 | 
            -
                                    placeholder=" | 
| 110 | 
            -
             | 
| 111 | 
            -
                                    lines=2,
         | 
| 112 | 
             
                                    type="password"
         | 
| 113 | 
             
                                ).style(container=False)
         | 
| 114 |  | 
| @@ -120,7 +124,7 @@ with gr.Blocks() as demo: | |
| 120 |  | 
| 121 |  | 
| 122 | 
             
                        with gr.Column(scale=0.1, min_width=0):
         | 
| 123 | 
            -
                            btn1 = gr.Button(" | 
| 124 |  | 
| 125 | 
             
                with gr.Row():
         | 
| 126 | 
             
                    with gr.Column(scale=0.85):
         | 
| @@ -204,6 +208,6 @@ with gr.Blocks() as demo: | |
| 204 |  | 
| 205 |  | 
| 206 | 
             
            demo.queue()
         | 
| 207 | 
            -
            demo.launch()
         | 
| 208 |  | 
| 209 |  | 
|  | |
| 47 | 
             
                def run(self, messages):
         | 
| 48 | 
             
                    if self.OPENAI_KEY == '' and self.OPENAI_API_KEY_AZURE == '':
         | 
| 49 | 
             
                        yield '', np.zeros((100, 100, 3), dtype=np.uint8), "Please set your OpenAI API key first!!!", pd.DataFrame()
         | 
| 50 | 
            +
                    elif len(self.OPENAI_KEY) >= 0 and not self.OPENAI_KEY.startswith('sk') and self.OPENAI_API_KEY_AZURE == '':
         | 
| 51 | 
            +
                        yield '', np.zeros((100, 100, 3), dtype=np.uint8), "Your openai key is incorrect!!!", pd.DataFrame()
         | 
| 52 | 
             
                    else:
         | 
| 53 | 
             
                        # self.stop = False
         | 
| 54 | 
             
                        gen = gradio_interface(messages, self.OPENAI_KEY, self.OPENAI_API_KEY_AZURE, self.OPENAI_API_BASED_AZURE, self.OPENAI_ENGINE_AZURE)
         | 
|  | |
| 85 | 
             
                if not OPENAI_KEY:
         | 
| 86 | 
             
                    with gr.Row().style():
         | 
| 87 | 
             
                        with gr.Column(scale=0.95):
         | 
| 88 | 
            +
                            gr.Markdown(
         | 
| 89 | 
            +
                                """
         | 
| 90 | 
            +
                                You can use gpt35 from openai or from openai-azure.
         | 
| 91 | 
            +
                                """)
         | 
| 92 | 
             
                            openai_api_key = gr.Textbox(
         | 
| 93 | 
             
                                show_label=False,
         | 
| 94 | 
             
                                placeholder="Set your OpenAI API key here and press Submit  (e.g. sk-xxx)",
         | 
|  | |
| 99 | 
             
                            with gr.Row():
         | 
| 100 | 
             
                                openai_api_key_azure = gr.Textbox(
         | 
| 101 | 
             
                                    show_label=False,
         | 
| 102 | 
            +
                                    placeholder="Set your Azure-OpenAI key",
         | 
| 103 | 
             
                                    lines=1,
         | 
| 104 | 
             
                                    type="password"
         | 
| 105 | 
             
                                ).style(container=False)
         | 
| 106 | 
             
                                openai_api_base_azure = gr.Textbox(
         | 
| 107 | 
             
                                    show_label=False,
         | 
| 108 | 
            +
                                    placeholder="Azure-OpenAI api_base (e.g. https://zwq0525.openai.azure.com)",
         | 
| 109 | 
            +
                                    lines=1,
         | 
|  | |
| 110 | 
             
                                    type="password"
         | 
| 111 | 
             
                                ).style(container=False)
         | 
| 112 | 
             
                                openai_api_engine_azure = gr.Textbox(
         | 
| 113 | 
             
                                    show_label=False,
         | 
| 114 | 
            +
                                    placeholder="Azure-OpenAI engine here (e.g. gpt35)",
         | 
| 115 | 
            +
                                    lines=1,
         | 
|  | |
| 116 | 
             
                                    type="password"
         | 
| 117 | 
             
                                ).style(container=False)
         | 
| 118 |  | 
|  | |
| 124 |  | 
| 125 |  | 
| 126 | 
             
                        with gr.Column(scale=0.1, min_width=0):
         | 
| 127 | 
            +
                            btn1 = gr.Button("上传").style(full_height=True)
         | 
| 128 |  | 
| 129 | 
             
                with gr.Row():
         | 
| 130 | 
             
                    with gr.Column(scale=0.85):
         | 
|  | |
| 208 |  | 
| 209 |  | 
| 210 | 
             
            demo.queue()
         | 
| 211 | 
            +
            demo.launch(share=True)
         | 
| 212 |  | 
| 213 |  |