File size: 4,062 Bytes
3cd105e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Quickstart Guide - Prompt A/B Tester

## Local Development

### 1. Install Dependencies

```bash

pip install -r requirements.txt

```

### 2. Configure API Key (Option A: Secrets)

Create `.streamlit/secrets.toml`:

```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

```bash

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

1. Go to https://huggingface.co/spaces
2. Click "Create new Space"
3. 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

1. Go to your Space β†’ Settings β†’ Repository secrets
2. Click "Add a secret"
3. Enter:
   - **Name**: `OPENAI_API_KEY`
   - **Value**: Your OpenAI API key (e.g., `sk-...`)
4. 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

1. Choose input method:
   - **Upload files**: Two `.md` or `.txt` files
   - **Paste text**: Directly in text areas
2. Click "πŸš€ Uruchom Test"
3. Wait for generation (progress bar shows status)

### Step 3: Rate Responses

1. Review each generated response
2. Rate 1-5:
   - 1 = Very poor
   - 2 = Poor
   - 3 = Average
   - 4 = Good
   - 5 = Excellent
3. 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

1. **Start small**: Use 3-5 responses for initial tests
2. **Use gpt-4o**: Best quality/cost ratio ($0.05 per 10 responses)
3. **Check cost**: Use "πŸ’° Szacuj koszt" before running large tests
4. **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