Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,9 +1,7 @@ | |
| 1 | 
             
            import gradio as gr
         | 
| 2 | 
             
            from huggingface_hub import InferenceClient
         | 
|  | |
| 3 |  | 
| 4 | 
            -
            """
         | 
| 5 | 
            -
            For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
         | 
| 6 | 
            -
            """
         | 
| 7 | 
             
            client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
         | 
| 8 |  | 
| 9 |  | 
| @@ -15,6 +13,7 @@ def respond( | |
| 15 | 
             
                temperature,
         | 
| 16 | 
             
                top_p,
         | 
| 17 | 
             
            ):
         | 
|  | |
| 18 | 
             
                messages = [{"role": "system", "content": system_message}]
         | 
| 19 |  | 
| 20 | 
             
                for val in history:
         | 
| @@ -25,8 +24,10 @@ def respond( | |
| 25 |  | 
| 26 | 
             
                messages.append({"role": "user", "content": message})
         | 
| 27 |  | 
|  | |
| 28 | 
             
                response = ""
         | 
| 29 |  | 
|  | |
| 30 | 
             
                for message in client.chat_completion(
         | 
| 31 | 
             
                    messages,
         | 
| 32 | 
             
                    max_tokens=max_tokens,
         | 
| @@ -35,14 +36,11 @@ def respond( | |
| 35 | 
             
                    top_p=top_p,
         | 
| 36 | 
             
                ):
         | 
| 37 | 
             
                    token = message.choices[0].delta.content
         | 
| 38 | 
            -
             | 
| 39 | 
             
                    response += token
         | 
| 40 | 
             
                    yield response
         | 
| 41 |  | 
| 42 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
            For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
         | 
| 45 | 
            -
            """
         | 
| 46 | 
             
            demo = gr.ChatInterface(
         | 
| 47 | 
             
                respond,
         | 
| 48 | 
             
                additional_inputs=[
         | 
| @@ -59,6 +57,8 @@ demo = gr.ChatInterface( | |
| 59 | 
             
                ],
         | 
| 60 | 
             
            )
         | 
| 61 |  | 
| 62 | 
            -
             | 
| 63 | 
             
            if __name__ == "__main__":
         | 
| 64 | 
            -
                demo.launch(share=True)
         | 
|  | |
|  | 
|  | |
| 1 | 
             
            import gradio as gr
         | 
| 2 | 
             
            from huggingface_hub import InferenceClient
         | 
| 3 | 
            +
            import os
         | 
| 4 |  | 
|  | |
|  | |
|  | |
| 5 | 
             
            client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
         | 
| 6 |  | 
| 7 |  | 
|  | |
| 13 | 
             
                temperature,
         | 
| 14 | 
             
                top_p,
         | 
| 15 | 
             
            ):
         | 
| 16 | 
            +
                # Prepare messages for the API
         | 
| 17 | 
             
                messages = [{"role": "system", "content": system_message}]
         | 
| 18 |  | 
| 19 | 
             
                for val in history:
         | 
|  | |
| 24 |  | 
| 25 | 
             
                messages.append({"role": "user", "content": message})
         | 
| 26 |  | 
| 27 | 
            +
                # Initialize response variable
         | 
| 28 | 
             
                response = ""
         | 
| 29 |  | 
| 30 | 
            +
                # Call the InferenceClient with chat_completion
         | 
| 31 | 
             
                for message in client.chat_completion(
         | 
| 32 | 
             
                    messages,
         | 
| 33 | 
             
                    max_tokens=max_tokens,
         | 
|  | |
| 36 | 
             
                    top_p=top_p,
         | 
| 37 | 
             
                ):
         | 
| 38 | 
             
                    token = message.choices[0].delta.content
         | 
|  | |
| 39 | 
             
                    response += token
         | 
| 40 | 
             
                    yield response
         | 
| 41 |  | 
| 42 |  | 
| 43 | 
            +
            # Create the Gradio ChatInterface
         | 
|  | |
|  | |
| 44 | 
             
            demo = gr.ChatInterface(
         | 
| 45 | 
             
                respond,
         | 
| 46 | 
             
                additional_inputs=[
         | 
|  | |
| 57 | 
             
                ],
         | 
| 58 | 
             
            )
         | 
| 59 |  | 
| 60 | 
            +
            # Launch the Gradio app and print the URL
         | 
| 61 | 
             
            if __name__ == "__main__":
         | 
| 62 | 
            +
                demo.launch(share=True)  # Set to True to share on Hugging Face Spaces
         | 
| 63 | 
            +
                # Print the URL for the Hugging Face Space
         | 
| 64 | 
            +
                print(f"Your Hugging Face Space is live at: {os.environ['SPACE_URL']}")
         | 

