File size: 2,950 Bytes
26f6e80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Spring Boot Application for Hugging Face Spaces

A simple Spring Boot REST API application designed to be deployed on Hugging Face Spaces.

## Features

- REST API with multiple endpoints
- Health check endpoint for monitoring
- Containerized with Docker
- Configured for Hugging Face Spaces deployment (port 7860)

## API Endpoints

### GET /api/
Returns a welcome message with current status.

**Response:**
```json
{
  "message": "Welcome to Spring Boot on Hugging Face!",
  "status": "running",
  "timestamp": "2024-11-13T10:30:00"
}
```

### GET /api/greeting
Returns a personalized greeting.

**Parameters:**
- `name` (optional): Name for the greeting (default: "World")

**Example:** `/api/greeting?name=John`

**Response:**
```json
{
  "greeting": "Hello, John!",
  "timestamp": "2024-11-13T10:30:00"
}
```

### GET /api/health
Health check endpoint.

**Response:**
```json
{
  "status": "UP",
  "service": "Spring Boot Demo"
}
```

### POST /api/echo
Echoes back the received JSON payload.

**Request Body:**
```json
{
  "message": "test",
  "data": "example"
}
```

**Response:**
```json
{
  "received": {
    "message": "test",
    "data": "example"
  },
  "timestamp": "2024-11-13T10:30:00"
}
```

## Local Development

### Prerequisites
- Java 17 or higher
- Maven 3.6 or higher

### Running Locally

1. Clone the repository
2. Navigate to the project directory
3. Run the application:
   ```bash
   mvn spring-boot:run
   ```
4. Access the application at `http://localhost:7860/api/`

### Building the JAR
```bash
mvn clean package
```

### Running with Docker
```bash
# Build the Docker image
docker build -t springboot-hf-demo .

# Run the container
docker run -p 7860:7860 springboot-hf-demo
```

## Deploying to Hugging Face Spaces

1. Create a new Space on Hugging Face
2. Choose "Docker" as the SDK
3. Upload these files to your Space repository:
   - `Dockerfile`
   - `pom.xml`
   - `src/` directory with all Java files and resources
   - `README.md`

4. The Space will automatically build and deploy your application

### Hugging Face Configuration

The application is configured to:
- Listen on port 7860 (required by Hugging Face)
- Bind to all network interfaces (0.0.0.0)
- Run as a non-root user for security

## Project Structure

```
springboot-app/
β”œβ”€β”€ src/
β”‚   └── main/
β”‚       β”œβ”€β”€ java/
β”‚       β”‚   └── com/example/demo/
β”‚       β”‚       β”œβ”€β”€ DemoApplication.java
β”‚       β”‚       └── controller/
β”‚       β”‚           └── GreetingController.java
β”‚       └── resources/
β”‚           └── application.properties
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ pom.xml
└── README.md
```

## Technologies Used

- Spring Boot 3.2.1
- Java 17
- Maven
- Docker
- Spring Web
- Spring Boot Actuator

## License

This project is open source and available for educational purposes.

## Contributing

Feel free to fork this project and customize it for your needs!