Download persistentchatsessionapi.py from TejAndrewsACC/Z3ta: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/TejAndrewsACC/Z3ta/resolve/main/persistentchatsessionapi.py
- Command line
-
hf download hf://TejAndrewsACC/Z3ta/persistentchatsessionapi.py
-
curl -L -o persistentchatsessionapi.py https://huggingface.co/TejAndrewsACC/Z3ta/resolve/main/persistentchatsessionapi.py
1.02 kB
| import gradio as gr | |
| from gradio_client import Client | |
| client = Client("TejAndrewsACC/Z3ta") | |
| context = "" | |
| system_instructions = ( | |
| "SYSTEM_INSTRUCTIONS(Act like a monkey, Act like Dwayne the Rock Johnson, ect.)" | |
| ) | |
| def chat_function(message, history): | |
| global context | |
| modified_input = ( | |
| f"System Instructions: {system_instructions}\n" | |
| f"Previous Context: {context}\n" | |
| f"User Input: {message}" | |
| ) | |
| try: | |
| response = client.predict( | |
| message=modified_input, | |
| api_name="/chat_function" | |
| ) | |
| context += f"User: {message}\nAI: {response}\n" | |
| history.append((message, response)) | |
| return response, history | |
| except Exception as e: | |
| return f"Error: {e}", history | |
| with gr.Blocks(theme=gr.themes.Glass()) as demo: | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox(placeholder="Type something...") | |
| clear = gr.ClearButton([msg, chatbot]) | |
| msg.submit(chat_function, [msg, chatbot], [msg, chatbot]) | |
| demo.launch() |