Spaces:
Runtime error
Runtime error
Download app.py from QL2023/web_base_stream: direct link, hf CLI and curl.
- Browser
- Download file 987 Bytes
-
https://huggingface.co/spaces/QL2023/web_base_stream/resolve/main/app.py
- Command line
-
hf download hf://spaces/QL2023/web_base_stream/app.py
-
curl -L -o app.py https://huggingface.co/spaces/QL2023/web_base_stream/resolve/main/app.py
987 Bytes
| import gradio as gr | |
| import requests | |
| import os | |
| root = os.environ["ROOT"] | |
| ############################################################# | |
| thread = "" | |
| while not thread.startswith("thread"): | |
| url = root + "/api/create" | |
| PARAMS = {'context1':"context1"} | |
| response = requests.get( | |
| url, | |
| stream=True, | |
| headers={"accept": "*/*"}, | |
| params = PARAMS | |
| ) | |
| for chunk in response.iter_content(chunk_size=512): | |
| thread = str(chunk, encoding="utf-8") | |
| def predict(message, history): | |
| url = root + "/api/chat" | |
| PARAMS = {'query':message, | |
| 'thread':thread, | |
| 'context1':"context1", | |
| 'context2':"context2"} | |
| response = requests.get( | |
| url, | |
| stream=True, | |
| headers={"accept": "*/*"}, | |
| params = PARAMS | |
| ) | |
| partial_message = "" | |
| for chunk in response: | |
| if chunk: | |
| partial_message = partial_message + str(chunk, encoding="utf-8") | |
| yield partial_message | |
| gr.ChatInterface(predict).launch() |