SharvNey commited on
Commit
a002d8f
Β·
verified Β·
1 Parent(s): 984abd6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +209 -0
README.md CHANGED
@@ -8,5 +8,214 @@ sdk_version: 6.2.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
+ # 🧠 Prompt Optimization Tool using Generative AI
12
+
13
+ A production-ready **GenAI application** that automatically improves user prompts, evaluates multiple prompt variants, and selects the best-performing one using an intelligent scoring framework.
14
+
15
+ This project demonstrates **modern prompt engineering, LLM integration, and automated evaluation** in a real-world deployed system.
16
+
17
+ ---
18
+
19
+ ## πŸš€ Features
20
+
21
+ - ✨ Generates multiple **optimized prompt variants**
22
+ - πŸ€– Uses a **Large Language Model (LLM)** to produce responses
23
+ - πŸ“Š Automatically **evaluates outputs** using:
24
+ - Semantic similarity
25
+ - Conciseness
26
+ - LLM-based judgment
27
+ - πŸ† Selects the **best prompt** automatically
28
+ - 🌐 Interactive **Gradio web interface**
29
+ - πŸ” Secure token handling using **environment variables**
30
+ - ☁️ Deployable on **Hugging Face Spaces**
31
+
32
+ ---
33
+
34
+ ## πŸ—οΈ System Architecture
35
+
36
+ ```
37
+ User Input
38
+ ↓
39
+ Prompt Variant Generator
40
+ ↓
41
+ LLM (Mistral-7B-Instruct)
42
+ ↓
43
+ Automatic Evaluator
44
+ ↓
45
+ Scoring Engine
46
+ ↓
47
+ Best Prompt Selection
48
+ ↓
49
+ Gradio Web Interface
50
+ ```
51
+
52
+ ---
53
+
54
+ ## πŸ› οΈ Tech Stack
55
+
56
+ | Layer | Technology |
57
+ |------|------------|
58
+ Frontend | Gradio
59
+ Backend | Python
60
+ LLM | Mistral-7B-Instruct (Hugging Face Inference API)
61
+ Evaluation | Sentence Transformers, Scikit-learn
62
+ Deployment | Hugging Face Spaces
63
+ Security | Environment variables & HF Secrets
64
+
65
+ ---
66
+
67
+ ## πŸ“ Project Structure
68
+
69
+ ```
70
+ .
71
+ β”œβ”€β”€ app.py # Gradio UI
72
+ β”œβ”€β”€ backend.py # LLM connection + prompt variant generator
73
+ β”œβ”€β”€ evaluator.py # Automatic scoring logic
74
+ β”œβ”€β”€ optimizer.py # Core optimization engine
75
+ β”œβ”€β”€ requirements.txt # Project dependencies
76
+ └── README.md # Project documentation
77
+ ```
78
+
79
+ ---
80
+
81
+ ## βš™οΈ Installation (Local / Colab)
82
+
83
+ ### 1️⃣ Clone the repository
84
+ ```bash
85
+ git clone <your-repo-url>
86
+ cd prompt-optimization-tool
87
+ ```
88
+
89
+ ### 2️⃣ Install dependencies
90
+ ```bash
91
+ pip install -r requirements.txt
92
+ ```
93
+
94
+ ### 3️⃣ Set Hugging Face token
95
+
96
+ Create a token at:
97
+ πŸ‘‰ https://huggingface.co/settings/tokens (Role: **Read**)
98
+
99
+ Then set it in your environment:
100
+
101
+ **Linux / Mac**
102
+ ```bash
103
+ export HF_TOKEN=hf_your_token_here
104
+ ```
105
+
106
+ **Windows (PowerShell)**
107
+ ```powershell
108
+ setx HF_TOKEN "hf_your_token_here"
109
+ ```
110
+
111
+ **Google Colab**
112
+ ```python
113
+ import os
114
+ os.environ["HF_TOKEN"] = "hf_your_token_here"
115
+ ```
116
+
117
+ ---
118
+
119
+ ## ▢️ Running the App
120
+
121
+ ```bash
122
+ python app.py
123
+ ```
124
+
125
+ Open the link shown in the terminal to use the web interface.
126
+
127
+ ---
128
+
129
+ ## 🌐 Deployment on Hugging Face Spaces
130
+
131
+ 1. Go to: https://huggingface.co/spaces
132
+ 2. Create a new Space β†’ **SDK: Gradio**
133
+ 3. Upload these files:
134
+ - `app.py`
135
+ - `backend.py`
136
+ - `evaluator.py`
137
+ - `optimizer.py`
138
+ - `requirements.txt`
139
+ 4. Add your token:
140
+ - Space β†’ **Settings β†’ Repository secrets**
141
+ ```
142
+ HF_TOKEN = hf_your_token_here
143
+ ```
144
+ 5. Restart the Space
145
+ 6. Your app is now live πŸŽ‰
146
+
147
+ ---
148
+
149
+ ## πŸ§ͺ Example Test Cases
150
+
151
+ ### Prompt
152
+ ```
153
+ Explain gradient descent
154
+ ```
155
+
156
+ ### Reference (optional)
157
+ ```
158
+ Gradient descent is an optimization algorithm that minimizes a loss function by iteratively updating parameters in the direction of the negative gradient.
159
+ ```
160
+
161
+ ### Output
162
+ - Best optimized prompt
163
+ - Ranked prompt variants
164
+ - Model-generated answers
165
+ - Scores for each variant
166
+
167
+ ---
168
+
169
+ ## πŸ” Security Notes
170
+
171
+ - ❌ Never hard-code API keys or tokens
172
+ - βœ… Always use **environment variables** or **Hugging Face secrets**
173
+ - πŸ”„ Rotate tokens if exposed
174
+
175
+ ---
176
+
177
+ ## πŸ“ˆ Why this project is unique
178
+
179
+ Instead of only generating text, this system:
180
+
181
+ - **Evaluates prompt quality automatically**
182
+ - Uses **LLM-as-a-judge**
183
+ - Applies **semantic similarity scoring**
184
+ - Implements **real optimization logic**
185
+ - Is fully **deployable in production**
186
+
187
+ This makes it a strong example of **applied Generative AI engineering**.
188
+
189
+ ---
190
+
191
+ ## πŸŽ“ Use Cases
192
+
193
+ - Prompt engineering research
194
+ - GenAI tooling
195
+ - AI assistant improvement
196
+ - Educational demonstrations
197
+ - Hackathons & academic projects
198
+
199
+ ---
200
+
201
+ ## πŸ“„ License
202
+
203
+ This project is for **educational and research purposes**.
204
+ You are free to modify and extend it.
205
+
206
+ ---
207
+
208
+ ## πŸ™Œ Acknowledgements
209
+
210
+ - Hugging Face for the Inference API
211
+ - Mistral AI for the open-source model
212
+ - Gradio for the UI framework
213
+
214
+ ---
215
+
216
+ ## πŸ‘¨β€πŸ’» Author
217
+
218
+ **Sharv Mehta**
219
+ Prompt Optimization Tool using Generative AI
220
 
221
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference