Spaces:
Configuration error
Configuration error
Delete README.md
Browse files
README.md
DELETED
|
@@ -1,185 +0,0 @@
|
|
| 1 |
-
# LaTeX-Enhanced Document Backend
|
| 2 |
-
|
| 3 |
-
AI-powered document enhancement backend with LaTeX support using Google Gemini API.
|
| 4 |
-
|
| 5 |
-
## 🚀 Features
|
| 6 |
-
|
| 7 |
-
- **AI-Powered Enhancement**: Uses Google Gemini to improve document quality
|
| 8 |
-
- **LaTeX Support**: Automatically formats mathematical equations and scientific notation
|
| 9 |
-
- **Multiple Formats**: Supports DOCX, PDF, and TXT input files
|
| 10 |
-
- **Professional Output**: Generates well-formatted, professional documents
|
| 11 |
-
- **Cloud-Ready**: Designed for HuggingFace Spaces deployment
|
| 12 |
-
|
| 13 |
-
## 📋 Prerequisites
|
| 14 |
-
|
| 15 |
-
- Google Gemini API Key ([Get one here](https://makersuite.google.com/app/apikey))
|
| 16 |
-
- HuggingFace Account ([Sign up](https://huggingface.co/join))
|
| 17 |
-
|
| 18 |
-
## 🎯 HuggingFace Spaces Deployment
|
| 19 |
-
|
| 20 |
-
### Step 1: Create a New Space
|
| 21 |
-
|
| 22 |
-
1. Go to [HuggingFace Spaces](https://huggingface.co/new-space)
|
| 23 |
-
2. Choose a name for your Space
|
| 24 |
-
3. Select **Docker** as the Space SDK
|
| 25 |
-
4. Choose visibility (Public or Private)
|
| 26 |
-
5. Click **Create Space**
|
| 27 |
-
|
| 28 |
-
### Step 2: Upload Files
|
| 29 |
-
|
| 30 |
-
Upload all files from the `backend` folder to your Space:
|
| 31 |
-
- `app.py`
|
| 32 |
-
- `gemini_client.py`
|
| 33 |
-
- `latex_processor.py`
|
| 34 |
-
- `document_converter.py`
|
| 35 |
-
- `requirements.txt`
|
| 36 |
-
- `Dockerfile`
|
| 37 |
-
- `README.md` (this file)
|
| 38 |
-
|
| 39 |
-
### Step 3: Set Environment Variables
|
| 40 |
-
|
| 41 |
-
1. Go to your Space's **Settings**
|
| 42 |
-
2. Navigate to **Repository secrets**
|
| 43 |
-
3. Add a new secret:
|
| 44 |
-
- Name: `GEMINI_API_KEY`
|
| 45 |
-
- Value: Your Google Gemini API key
|
| 46 |
-
|
| 47 |
-
### Step 4: Deploy
|
| 48 |
-
|
| 49 |
-
Your Space will automatically build and deploy! Wait for the build to complete (usually 2-5 minutes).
|
| 50 |
-
|
| 51 |
-
### Step 5: Get Your API URL
|
| 52 |
-
|
| 53 |
-
Once deployed, your backend will be available at:
|
| 54 |
-
```
|
| 55 |
-
https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space
|
| 56 |
-
```
|
| 57 |
-
|
| 58 |
-
Example: `https://omgy-doc-enhancer.hf.space`
|
| 59 |
-
|
| 60 |
-
## 🔧 API Endpoints
|
| 61 |
-
|
| 62 |
-
### Health Check
|
| 63 |
-
```
|
| 64 |
-
GET /health
|
| 65 |
-
```
|
| 66 |
-
|
| 67 |
-
Returns server status.
|
| 68 |
-
|
| 69 |
-
### Enhance Document
|
| 70 |
-
```
|
| 71 |
-
POST /enhance
|
| 72 |
-
```
|
| 73 |
-
|
| 74 |
-
**Parameters:**
|
| 75 |
-
- `file`: Document file (DOCX, PDF, or TXT)
|
| 76 |
-
- `prompt` (optional): Enhancement instructions
|
| 77 |
-
- `doc_type` (optional): Document type hint (auto, academic, technical, business)
|
| 78 |
-
|
| 79 |
-
**Example with curl:**
|
| 80 |
-
```bash
|
| 81 |
-
curl -X POST https://your-space.hf.space/enhance \
|
| 82 |
-
-F "file=@document.docx" \
|
| 83 |
-
-F "prompt=Make this more professional and add LaTeX for equations"
|
| 84 |
-
```
|
| 85 |
-
|
| 86 |
-
**Response:**
|
| 87 |
-
Enhanced document file (same format as input)
|
| 88 |
-
|
| 89 |
-
### API Info
|
| 90 |
-
```
|
| 91 |
-
GET /
|
| 92 |
-
```
|
| 93 |
-
|
| 94 |
-
Returns API information and available features.
|
| 95 |
-
|
| 96 |
-
## 🧪 Local Testing (Optional)
|
| 97 |
-
|
| 98 |
-
If you want to test locally before deploying:
|
| 99 |
-
|
| 100 |
-
1. Install Python 3.11+
|
| 101 |
-
2. Install dependencies:
|
| 102 |
-
```bash
|
| 103 |
-
pip install -r requirements.txt
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
3. Create `.env` file:
|
| 107 |
-
```bash
|
| 108 |
-
cp .env.example .env
|
| 109 |
-
```
|
| 110 |
-
Then edit `.env` and add your `GEMINI_API_KEY`
|
| 111 |
-
|
| 112 |
-
4. Run the app:
|
| 113 |
-
```bash
|
| 114 |
-
python app.py
|
| 115 |
-
```
|
| 116 |
-
|
| 117 |
-
5. Test at `http://localhost:7860`
|
| 118 |
-
|
| 119 |
-
## 📖 LaTeX Support
|
| 120 |
-
|
| 121 |
-
The backend automatically detects mathematical content and formats it using LaTeX:
|
| 122 |
-
|
| 123 |
-
- **Inline equations**: `$E = mc^2$`
|
| 124 |
-
- **Display equations**: `$$\int_0^\infty e^{-x} dx = 1$$`
|
| 125 |
-
- **Matrices**: `$$\begin{matrix} a & b \\ c & d \end{matrix}$$`
|
| 126 |
-
- **Symbols**: α, β, γ, ∫, ∑, ∏, √, ∞, etc.
|
| 127 |
-
|
| 128 |
-
## 🎨 Document Types
|
| 129 |
-
|
| 130 |
-
Specify `doc_type` for optimized enhancement:
|
| 131 |
-
|
| 132 |
-
- `auto`: Automatic detection (default)
|
| 133 |
-
- `academic`: Research papers, theses
|
| 134 |
-
- `technical`: Technical documentation, manuals
|
| 135 |
-
- `business`: Business reports, proposals
|
| 136 |
-
|
| 137 |
-
## ⚙️ Configuration
|
| 138 |
-
|
| 139 |
-
Environment variables (set in HuggingFace Spaces secrets):
|
| 140 |
-
|
| 141 |
-
| Variable | Required | Description |
|
| 142 |
-
|----------|----------|-------------|
|
| 143 |
-
| `GEMINI_API_KEY` | Yes | Your Google Gemini API key |
|
| 144 |
-
| `FLASK_ENV` | No | Environment (production/development) |
|
| 145 |
-
| `PORT` | No | Server port (default: 7860) |
|
| 146 |
-
|
| 147 |
-
## 🐛 Troubleshooting
|
| 148 |
-
|
| 149 |
-
### Build Fails
|
| 150 |
-
- Check that all files are uploaded
|
| 151 |
-
- Verify Dockerfile syntax
|
| 152 |
-
- Check HuggingFace Spaces logs
|
| 153 |
-
|
| 154 |
-
### API Returns Errors
|
| 155 |
-
- Verify `GEMINI_API_KEY` is set correctly in secrets
|
| 156 |
-
- Check API key is valid at [Google AI Studio](https://makersuite.google.com/)
|
| 157 |
-
- Review Space logs for detailed error messages
|
| 158 |
-
|
| 159 |
-
### Document Processing Fails
|
| 160 |
-
- Ensure file format is supported (.docx, .pdf, .txt)
|
| 161 |
-
- Check file is not corrupted
|
| 162 |
-
- Verify file size is reasonable (< 10MB recommended)
|
| 163 |
-
|
| 164 |
-
## 📚 Tech Stack
|
| 165 |
-
|
| 166 |
-
- **Flask**: Web framework
|
| 167 |
-
- **Google Gemini**: AI enhancement
|
| 168 |
-
- **python-docx**: DOCX processing
|
| 169 |
-
- **PyPDF2**: PDF processing
|
| 170 |
-
- **Gunicorn**: Production WSGI server
|
| 171 |
-
|
| 172 |
-
## 📄 License
|
| 173 |
-
|
| 174 |
-
This project is open source and available for modification.
|
| 175 |
-
|
| 176 |
-
## 🤝 Support
|
| 177 |
-
|
| 178 |
-
For issues or questions:
|
| 179 |
-
1. Check the troubleshooting section above
|
| 180 |
-
2. Review HuggingFace Spaces logs
|
| 181 |
-
3. Check that your Gemini API key is valid
|
| 182 |
-
|
| 183 |
-
---
|
| 184 |
-
|
| 185 |
-
**Made with ♥ using Google Gemini and HuggingFace Spaces**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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