Spaces:
Running
A newer version of the Streamlit SDK is available:
1.53.1
Quickstart Guide - Prompt A/B Tester
Local Development
1. Install Dependencies
pip install -r requirements.txt
2. Configure API Key (Option A: Secrets)
Create .streamlit/secrets.toml:
OPENAI_API_KEY = "sk-your-actual-api-key"
β οΈ Important: Never commit secrets.toml to Git!
3. Configure API Key (Option B: In-App)
Skip step 2 and enter API key directly in the sidebar when the app starts.
4. Run Application
streamlit run app.py
The app will open automatically in your browser at http://localhost:8501
Deployment on Hugging Face Spaces
1. Create New Space
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Choose:
- Space name: your-space-name
- SDK: Streamlit
- Visibility: Public or Private
2. Upload Files
Upload all files from HuggingFace_App/ directory:
app.py
config.py
api_handler.py
test_runner.py
requirements.txt
README.md
.gitignore
Do NOT upload:
.streamlit/secrets.toml(use Repository secrets instead)__pycache__/directories
3. Configure Secret
- Go to your Space β Settings β Repository secrets
- Click "Add a secret"
- Enter:
- Name:
OPENAI_API_KEY - Value: Your OpenAI API key (e.g.,
sk-...)
- Name:
- Save
4. Wait for Build
Your Space will automatically build and deploy. Check the build logs for any errors.
5. Access Your App
Your app will be available at: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
Usage Flow
Step 1: Configure (Sidebar)
- API Key: Auto-loaded from secrets or enter manually
- Model: Select GPT model (gpt-4o recommended)
- Temperature: 0.1 for deterministic, 0.7 for creative
- Max Tokens: 2000 (typical for medical/technical prompts)
- Num Responses: 5 for quick test, 10-20 for reliable statistics
Step 2: Run Test
- Choose input method:
- Upload files: Two
.mdor.txtfiles - Paste text: Directly in text areas
- Upload files: Two
- Click "π Uruchom Test"
- Wait for generation (progress bar shows status)
Step 3: Rate Responses
- Review each generated response
- Rate 1-5:
- 1 = Very poor
- 2 = Poor
- 3 = Average
- 4 = Good
- 5 = Excellent
- Click "π Oblicz Wyniki"
Step 4: View Results
- See statistics table (count, score, min, max)
- Identify winner (higher average score)
- Download CSV with full results and metadata
Troubleshooting
Error: "Invalid API key"
Solution: Check your API key in Hugging Face Spaces secrets or re-enter in sidebar.
Error: "Rate limit exceeded"
Solution: Wait 1-2 minutes before retrying. Reduce number of responses if problem persists.
Error: "Insufficient quota"
Solution: Add funds to your OpenAI account at https://platform.openai.com/account/billing
App is slow
Expected behavior: Each response takes 3-10 seconds to generate. Total time for 10 responses (5A + 5B) β 1-2 minutes.
Cost Optimization Tips
- Start small: Use 3-5 responses for initial tests
- Use gpt-4o: Best quality/cost ratio ($0.05 per 10 responses)
- Check cost: Use "π° Szacuj koszt" before running large tests
- Reduce max_tokens: If responses don't need to be long
Local vs Cloud Differences
| Feature | Local (Streamlit) | Hugging Face Spaces |
|---|---|---|
| API Key Storage | .streamlit/secrets.toml |
Repository secrets |
| Performance | Depends on your machine | Hugging Face servers |
| Cost | Free (only OpenAI API) | Free (only OpenAI API) |
| Accessibility | localhost:8501 | Public URL |
| SSL/HTTPS | No | Yes |
Support
For issues or questions:
- Check logs in "π Logi" tab
- Review Hugging Face Spaces build logs
- Verify OpenAI API key is valid and has funds
Version: 2.0 (Streamlit) Date: 2025-10-14