Spaces:
Runtime error
Runtime error
Download app.py from tchans123/al_chatbot: direct link, hf CLI and curl.
- Browser
- Download file 995 Bytes
-
https://huggingface.co/spaces/tchans123/al_chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/tchans123/al_chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/tchans123/al_chatbot/resolve/main/app.py
995 Bytes
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| import os | |
| # Initialize Hugging Face Inference Client | |
| client = InferenceClient( | |
| model="meta-llama/Meta-Llama-3.1-8B-Instruct", | |
| token=os.getenv("HUGGINGFACEHUB_API_TOKEN") # Token is retrieved from the Hugging Face secret | |
| ) | |
| # Function to interact with the model | |
| def ask_model(question): | |
| responses = [] | |
| for message in client.chat_completion( | |
| messages=[{"role": "user", "content": question}], | |
| max_tokens=1000, | |
| stream=True, | |
| ): | |
| responses.append(message.choices[0].delta.content) | |
| return ''.join(responses) | |
| # Gradio Interface | |
| interface = gr.Interface( | |
| fn=ask_model, | |
| inputs=gr.Textbox(lines=2, placeholder="Ask a question..."), | |
| outputs="text", | |
| title="Llama3.1 Based Ai Chatbot", | |
| description="Ask the model any question and get a response. Try out other models [here](https://huggingface.co/tchans123)." | |
| ) | |
| # Launch Gradio app | |
| interface.launch(share=True) | |