Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,14 +1,3 @@
|
|
| 1 |
-
*Thinking...*
|
| 2 |
-
> First, the user wants to update the Gradio app to use their OpenAI key. The current app is deployed at AiCoderv2/dark-app-74 on Hugging Face Spaces.
|
| 3 |
-
>
|
| 4 |
-
>
|
| 5 |
-
> ## Updating the Gradio App
|
| 6 |
-
> - The user aims to update their Gradio app to integrate their OpenAI key for functionality.
|
| 7 |
-
> - The app is currently deployed at AiCoderv2/dark-app-74 on Hugging Face Spaces, requiring code modifications.
|
| 8 |
-
|
| 9 |
-
I'll update the Gradio app to use your OpenAI API key securely. For Hugging Face Spaces, we'll use Space secrets instead of requiring users to enter their API key in the interface. This is more secure and convenient for deployment.
|
| 10 |
-
|
| 11 |
-
```python
|
| 12 |
import gradio as gr
|
| 13 |
import openai
|
| 14 |
import time
|
|
@@ -255,47 +244,4 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Chatbot with OpenAI") as demo:
|
|
| 255 |
|
| 256 |
# Launch the app
|
| 257 |
if __name__ == "__main__":
|
| 258 |
-
demo.launch(share=True)
|
| 259 |
-
```
|
| 260 |
-
|
| 261 |
-
## **Key Changes Made:**
|
| 262 |
-
|
| 263 |
-
### 🔐 **Secure API Key Handling**
|
| 264 |
-
- Now uses `OPENAI_API_KEY` environment variable
|
| 265 |
-
- Removes the API key input interface for security
|
| 266 |
-
- API key is set via Hugging Face Space secrets
|
| 267 |
-
|
| 268 |
-
### ⚙️ **Improved Configuration**
|
| 269 |
-
- Uses GPT-4o-mini as default (cost-effective)
|
| 270 |
-
- Added more model options including GPT-4o
|
| 271 |
-
- Increased max tokens to 2000 for longer responses
|
| 272 |
-
|
| 273 |
-
### 📊 **Status Indicator**
|
| 274 |
-
- Shows whether the chatbot is properly configured
|
| 275 |
-
- Provides immediate feedback on API key status
|
| 276 |
-
|
| 277 |
-
## **Setup Instructions for Your Space:**
|
| 278 |
-
|
| 279 |
-
1. **Go to your Space settings:**
|
| 280 |
-
- Visit: https://huggingface.co/spaces/AiCoderv2/dark-app-74/settings
|
| 281 |
-
- Go to "Secrets" tab
|
| 282 |
-
|
| 283 |
-
2. **Add your OpenAI API Key:**
|
| 284 |
-
- Name: `OPENAI_API_KEY`
|
| 285 |
-
- Value: Your OpenAI API key (starts with `sk-...`)
|
| 286 |
-
- Click "Add secret"
|
| 287 |
-
|
| 288 |
-
3. **Restart your Space:**
|
| 289 |
-
- The app will automatically use your API key
|
| 290 |
-
- The status indicator will show "✅ Chatbot is ready!"
|
| 291 |
-
|
| 292 |
-
## **Available Models:**
|
| 293 |
-
- **gpt-4o-mini**: Most cost-effective (~$0.15/1M input tokens)
|
| 294 |
-
- **gpt-4o**: Better quality (~$2.50/1M input tokens)
|
| 295 |
-
- **gpt-4-turbo**: Latest GPT-4 (~$10/1M input tokens)
|
| 296 |
-
- **gpt-4**: Original GPT-4 (~$30/1M input tokens)
|
| 297 |
-
|
| 298 |
-
## **Cost Monitoring:**
|
| 299 |
-
Monitor your OpenAI usage at: https://platform.openai.com/usage
|
| 300 |
-
|
| 301 |
-
The app is now updated and securely configured to use your OpenAI API key! Users can start chatting immediately without needing to enter API keys.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
import time
|
|
|
|
| 244 |
|
| 245 |
# Launch the app
|
| 246 |
if __name__ == "__main__":
|
| 247 |
+
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|