Spaces:
Runtime error
Runtime error
Download app.py from ravii-teja/bot: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/ravii-teja/bot/resolve/main/app.py
- Command line
-
hf download hf://spaces/ravii-teja/bot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ravii-teja/bot/resolve/main/app.py
1.99 kB
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| from bs4 import BeautifulSoup | |
| import requests | |
| client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") | |
| def scrape_content(urls): | |
| content = "" | |
| for url in urls: | |
| response = requests.get(url) | |
| soup = BeautifulSoup(response.text, 'html.parser') | |
| content += soup.get_text() + "\n\n" | |
| return content | |
| def respond( | |
| question, | |
| history: list[tuple[str, str]], | |
| system_message, | |
| max_tokens, | |
| temperature, | |
| top_p, | |
| ): | |
| # Hardcoded list of URLs | |
| urls = [ | |
| "https://dataos.info/getting_started/", | |
| "https://dataos.info/products/data_product/", | |
| "https://dataos.info/products/data_product/how_to_guides/", | |
| "https://dataos.info/products/data_product/core_concepts/", | |
| "https://dataos.info/products/data_product/configurations/" | |
| ] | |
| content = scrape_content(urls) | |
| messages = [{"role": "system", "content": system_message}] | |
| messages.append({"role": "user", "content": content}) | |
| messages.append({"role": "user", "content": question}) | |
| response = "" | |
| for message in client.chat_completion( | |
| messages, | |
| max_tokens=max_tokens, | |
| stream=True, | |
| temperature=temperature, | |
| top_p=top_p, | |
| ): | |
| token = message.choices[0].delta.content | |
| response += token | |
| yield response | |
| demo = gr.Interface( | |
| respond, | |
| inputs=[ | |
| gr.Textbox(label="Question"), | |
| gr.Textbox(value="You are a friendly Chatbot.", label="System message"), | |
| gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), | |
| gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), | |
| gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"), | |
| ], | |
| outputs="text", | |
| description="Ask questions about the content of multiple web pages." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |