KG
KG-GitHubRepo/AskZephyr
An interactive Q&A demo app using Streamlit and Hugging Face models. Features token authentication, chat and text-generation modes, and easy deployment to Hugging Face Spaces.
π€ Q&A Demo (Streamlit + Hugging Face)
A minimal Q&A web app built with Streamlit that calls the Hugging Face Inference API to generate answers from open-source LLMs.
It first tries a chat model and automatically falls back to a text-generation model if needed.
β¨ Features
- π₯ Streamlit UI β Clean and interactive interface
- π Secure API Authentication β Uses Hugging Face Access Tokens via environment variables
- π§ Two-stage model flow:
HuggingFaceH4/zephyr-7b-betaviachat_completion- Fallback:
tiiuae/falcon-7b-instructviatext_generation
- π¦ Error Handling β Displays clear error messages and status info
- π Deployable to Hugging Face Spaces with minimal setup
π Project Structure
.
βββ app.py # Main Streamlit application code
βββ requirements.txt # Python dependencies needed to run the app
βββ README.md # Project documentation
π Deploy to Hugging Face Spaces
1. Create a Space: https://huggingface.co/spaces
- SDK: Streamlit
- Runtime: Python 3.10+
2. Push code to Space repository
git remote add space https://huggingface.co/spaces/<username>/<space-name>
git push space main
3. Add your API token as a secret
- Go to Space β Settings β Repository secrets
- Add HUGGINGFACEHUB_API_TOKEN with your Hugging Face token value
4. Space will build and deploy automatically.
π§ How It Works
1. User enters a question in the input box.
2. App verifies Hugging Face token via HfApi().whoami().
3. Attempts to answer with chat_completion using Zephyr-7B.
4. If chat model fails, falls back to text_generation using Falcon-7B.
5. Displays the answer in the UI.
π Configuration
Environment Variable:
- HUGGINGFACEHUB_API_TOKEN (required, must start with hf_)
Models:
- Primary: HuggingFaceH4/zephyr-7b-beta
- Fallback: tiiuae/falcon-7b-instruct
Parameters:
- max_tokens / max_new_tokens: control output length
- temperature, top_p: adjust randomness
π©Ή Troubleshooting
Token Error:
- Ensure your token is valid and starts with hf_
- Check that it's exported in the same shell session
Model Error:
- Switch to another available model on Hugging Face
- Check modelβs Inference API page to confirm it supports chat or text generation
π€ Contributing
1. Fork the repository
2. Create your feature branch (git checkout -b feature/YourFeature)
3. Commit your changes (git commit -m "Add some feature")
4. Push to the branch (git push origin feature/YourFeature)
5. Open a Pull Request