File size: 4,236 Bytes
32bd536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---

title: Mistral Fine-tuned Model
emoji: πŸ€–
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
---


# πŸ€– Mistral Fine-tuned Model

Flask API with separate HTML/CSS/JS frontend for `KASHH-4/mistral_fine-tuned` model.

## πŸš€ What This Is

A **Flask API server** with **separate frontend files**:
- Backend: Python Flask with CORS
- Frontend: HTML + CSS + JavaScript  
- Clean separation of concerns
- API-first design

## πŸ“ Project Structure

```

e:\EDI\hf-node-app\

β”œβ”€β”€ app.py              # Main Gradio application

β”œβ”€β”€ requirements.txt    # Python dependencies

β”œβ”€β”€ README.md          # This file

└── .gitignore         # Git ignore rules

```

## πŸ”§ Deploy to Hugging Face Spaces

### Step 1: Create a Space

1. Go to https://huggingface.co/spaces
2. Click **"Create new Space"**
3. Configure:
   - **Owner:** KASHH-4 (or your account)
   - **Space name:** `mistral-api` (or any name)
   - **SDK:** Gradio
   - **Hardware:** CPU basic (Free)
   - **Visibility:** Public
4. Click **"Create Space"**

### Step 2: Upload Files

Upload these 3 files to your Space:
- `app.py`
- `requirements.txt`
- `README.md` (optional)

**Via Web UI:**
1. Click "Files" tab
2. Click "Add file" β†’ "Upload files"
3. Drag and drop the files
4. Commit changes

**Via Git:**
```bash

git init

git remote add origin https://huggingface.co/spaces/KASHH-4/mistral-api

git add app.py requirements.txt README.md .gitignore

git commit -m "Initial deployment"

git push origin main

```

### Step 3: Wait for Deployment

- First build takes 5-10 minutes
- Watch the logs for "Running on..."
- Your Space will be live at: `https://kashh-4-mistral-api.hf.space`

## πŸ§ͺ Test Your Space

### Web Interface
Visit: `https://huggingface.co/spaces/KASHH-4/mistral-api`

### API Endpoint
```bash

curl -X POST "https://kashh-4-mistral-api.hf.space/api/predict" \

  -H "Content-Type: application/json" \

  -d '{"data":["Hello, how are you?"]}'

```

### From JavaScript/Node.js
```javascript

const response = await fetch('https://kashh-4-mistral-api.hf.space/api/predict', {

  method: 'POST',

  headers: { 'Content-Type': 'application/json' },

  body: JSON.stringify({ data: ["Your prompt here"] })

});



const result = await response.json();

console.log(result.data[0]); // Generated text

```

### From Python
```python

import requests



response = requests.post(

    'https://kashh-4-mistral-api.hf.space/api/predict',

    json={'data': ['Your prompt here']}

)



print(response.json()['data'][0])

```

## πŸ’° Cost

**100% FREE** on HF Spaces:
- Free CPU tier (slower, ~10-30 sec per request)
- Sleeps after 48h inactivity (30 sec wake-up)
- Perfect for demos, personal projects, testing

**Optional Upgrades:**
- GPU T4 Small: $0.60/hour (much faster, 2-5 sec)
- GPU A10G: $3.15/hour (very fast, 1-2 sec)

Upgrade in: Space Settings β†’ Hardware

## πŸ”§ Local Testing (Optional)

If you have Python installed and want to test locally before deploying:

```bash

# Install dependencies

pip install -r requirements.txt



# Run locally

python app.py



# Visit: http://localhost:7860

```

**Requirements:**
- Python 3.9+
- 16GB+ RAM (for model loading)
- GPU recommended but not required

## πŸ“‹ Model Configuration

The app is configured for `KASHH-4/mistral_fine-tuned`. To use a different model, edit `app.py`:

```python

MODEL_NAME = "your-org/your-model"

```

## πŸ†˜ Troubleshooting

**Space stuck on "Building":**
- Check logs for errors
- Model might be too large for free CPU
- Try: Restart Space in Settings

**Space shows "Runtime Error":**
- Check if model exists and is public
- Verify model format is compatible with transformers
- Try smaller model first to test

**Slow responses:**
- Normal on free CPU tier
- Upgrade to GPU for faster inference
- Or use smaller model

## πŸ“ž Support

Issues? Check the deployment guide in `huggingface-space/DEPLOYMENT-GUIDE.md`

---

## πŸ—‘οΈ Cleanup Old Files

If you followed earlier Node.js instructions, delete unnecessary files:

See `CLEANUP.md` for full list of files to remove.

## License
MIT