Nambinintsoa Rovatiana RAMAROSON commited on
Commit ·
5a640eb
1
Parent(s): a17bef0
test
Browse files- Dockerfile +19 -0
- Gemfile +21 -0
- Gemfile.lock +69 -0
- README.md +15 -0
- Rakefile +16 -0
- app.rb +132 -0
- bin/server +4 -0
- config.ru +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dockerfile
|
| 2 |
+
FROM ruby:3.2.2-slim
|
| 3 |
+
|
| 4 |
+
# Installer les dépendances système
|
| 5 |
+
RUN apt-get update -qq && \
|
| 6 |
+
apt-get install -y --no-install-recommends \
|
| 7 |
+
build-essential \
|
| 8 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY Gemfile Gemfile.lock ./
|
| 13 |
+
RUN bundle install
|
| 14 |
+
|
| 15 |
+
COPY . .
|
| 16 |
+
|
| 17 |
+
EXPOSE 7860
|
| 18 |
+
|
| 19 |
+
CMD ["bundle", "exec", "ruby", "app.rb", "-o", "0.0.0.0", "-p", "7860"]
|
Gemfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gemfile
|
| 2 |
+
source "https://rubygems.org"
|
| 3 |
+
|
| 4 |
+
ruby "3.2.2" # Remplacez par votre version de Ruby
|
| 5 |
+
|
| 6 |
+
# Gems principales
|
| 7 |
+
gem "sinatra", "~> 3.0" # Framework web léger
|
| 8 |
+
gem "puma", "~> 6.0" # Serveur web
|
| 9 |
+
|
| 10 |
+
# Gems de développement
|
| 11 |
+
group :development do
|
| 12 |
+
gem "rake", "~> 13.0"
|
| 13 |
+
gem "rerun", "~> 0.14" # Redémarrage automatique
|
| 14 |
+
gem "pry", "~> 0.14" # Console interactive
|
| 15 |
+
end
|
| 16 |
+
|
| 17 |
+
# Gems pour les tests (optionnel)
|
| 18 |
+
group :test do
|
| 19 |
+
gem "rspec", "~> 3.12"
|
| 20 |
+
gem "rack-test", "~> 2.1"
|
| 21 |
+
end
|
Gemfile.lock
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GEM
|
| 2 |
+
remote: https://rubygems.org/
|
| 3 |
+
specs:
|
| 4 |
+
base64 (0.3.0)
|
| 5 |
+
coderay (1.1.3)
|
| 6 |
+
diff-lcs (1.6.2)
|
| 7 |
+
ffi (1.17.2-x64-mingw-ucrt)
|
| 8 |
+
listen (3.9.0)
|
| 9 |
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
| 10 |
+
rb-inotify (~> 0.9, >= 0.9.10)
|
| 11 |
+
method_source (1.1.0)
|
| 12 |
+
mustermann (3.0.4)
|
| 13 |
+
ruby2_keywords (~> 0.0.1)
|
| 14 |
+
nio4r (2.7.4)
|
| 15 |
+
pry (0.15.2)
|
| 16 |
+
coderay (~> 1.1)
|
| 17 |
+
method_source (~> 1.0)
|
| 18 |
+
puma (6.6.1)
|
| 19 |
+
nio4r (~> 2.0)
|
| 20 |
+
rack (2.2.17)
|
| 21 |
+
rack-protection (3.2.0)
|
| 22 |
+
base64 (>= 0.1.0)
|
| 23 |
+
rack (~> 2.2, >= 2.2.4)
|
| 24 |
+
rack-test (2.2.0)
|
| 25 |
+
rack (>= 1.3)
|
| 26 |
+
rake (13.3.0)
|
| 27 |
+
rb-fsevent (0.11.2)
|
| 28 |
+
rb-inotify (0.11.1)
|
| 29 |
+
ffi (~> 1.0)
|
| 30 |
+
rerun (0.14.0)
|
| 31 |
+
listen (~> 3.0)
|
| 32 |
+
rspec (3.13.1)
|
| 33 |
+
rspec-core (~> 3.13.0)
|
| 34 |
+
rspec-expectations (~> 3.13.0)
|
| 35 |
+
rspec-mocks (~> 3.13.0)
|
| 36 |
+
rspec-core (3.13.5)
|
| 37 |
+
rspec-support (~> 3.13.0)
|
| 38 |
+
rspec-expectations (3.13.5)
|
| 39 |
+
diff-lcs (>= 1.2.0, < 2.0)
|
| 40 |
+
rspec-support (~> 3.13.0)
|
| 41 |
+
rspec-mocks (3.13.5)
|
| 42 |
+
diff-lcs (>= 1.2.0, < 2.0)
|
| 43 |
+
rspec-support (~> 3.13.0)
|
| 44 |
+
rspec-support (3.13.5)
|
| 45 |
+
ruby2_keywords (0.0.5)
|
| 46 |
+
sinatra (3.2.0)
|
| 47 |
+
mustermann (~> 3.0)
|
| 48 |
+
rack (~> 2.2, >= 2.2.4)
|
| 49 |
+
rack-protection (= 3.2.0)
|
| 50 |
+
tilt (~> 2.0)
|
| 51 |
+
tilt (2.6.1)
|
| 52 |
+
|
| 53 |
+
PLATFORMS
|
| 54 |
+
x64-mingw-ucrt
|
| 55 |
+
|
| 56 |
+
DEPENDENCIES
|
| 57 |
+
pry (~> 0.14)
|
| 58 |
+
puma (~> 6.0)
|
| 59 |
+
rack-test (~> 2.1)
|
| 60 |
+
rake (~> 13.0)
|
| 61 |
+
rerun (~> 0.14)
|
| 62 |
+
rspec (~> 3.12)
|
| 63 |
+
sinatra (~> 3.0)
|
| 64 |
+
|
| 65 |
+
RUBY VERSION
|
| 66 |
+
ruby 3.2.2p53
|
| 67 |
+
|
| 68 |
+
BUNDLED WITH
|
| 69 |
+
2.6.3
|
README.md
CHANGED
|
@@ -8,3 +8,18 @@ pinned: false
|
|
| 8 |
---
|
| 9 |
|
| 10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 11 |
+
# Application Ruby Pure
|
| 12 |
+
|
| 13 |
+
Une application Ruby simple avec Sinatra, déployée sur Hugging Face.
|
| 14 |
+
|
| 15 |
+
## Utilisation
|
| 16 |
+
|
| 17 |
+
Ouvrez l'URL de votre Space et interagissez avec l'interface web.
|
| 18 |
+
|
| 19 |
+
## API Endpoints
|
| 20 |
+
|
| 21 |
+
- `GET /` - Interface web
|
| 22 |
+
- `GET /hello/:name` - Salutation
|
| 23 |
+
- `POST /users` - Créer utilisateur
|
| 24 |
+
- `GET /health` - Santé de l'app
|
| 25 |
+
- `GET /api` - Documentation
|
Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Rakefile
|
| 2 |
+
require "sinatra"
|
| 3 |
+
require "./app"
|
| 4 |
+
|
| 5 |
+
desc "Démarrer le serveur de développement"
|
| 6 |
+
task :start do
|
| 7 |
+
puts "Démarrage de l'application sur http://localhost:4567"
|
| 8 |
+
MonApp.run!
|
| 9 |
+
end
|
| 10 |
+
|
| 11 |
+
desc "Lancer la console interactive"
|
| 12 |
+
task :console do
|
| 13 |
+
require "pry"
|
| 14 |
+
ARGV.clear
|
| 15 |
+
Pry.start
|
| 16 |
+
end
|
app.rb
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.rb
|
| 2 |
+
require "sinatra"
|
| 3 |
+
require "json"
|
| 4 |
+
|
| 5 |
+
class MonApp < Sinatra::Base
|
| 6 |
+
configure do
|
| 7 |
+
set :port, 7860
|
| 8 |
+
set :bind, "0.0.0.0"
|
| 9 |
+
set :server, :puma
|
| 10 |
+
end
|
| 11 |
+
|
| 12 |
+
# Page d'accueil avec interface simple
|
| 13 |
+
get "/" do
|
| 14 |
+
content_type :html
|
| 15 |
+
<<~HTML
|
| 16 |
+
<!DOCTYPE html>
|
| 17 |
+
<html>
|
| 18 |
+
<head>
|
| 19 |
+
<title>Mon Application Ruby</title>
|
| 20 |
+
<style>
|
| 21 |
+
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
| 22 |
+
.container { background: #f5f5f5; padding: 20px; border-radius: 10px; }
|
| 23 |
+
input, button { padding: 10px; margin: 5px; }
|
| 24 |
+
.result { background: white; padding: 15px; border-radius: 5px; margin-top: 10px; }
|
| 25 |
+
</style>
|
| 26 |
+
</head>
|
| 27 |
+
<body>
|
| 28 |
+
<div class="container">
|
| 29 |
+
<h1>🚀 Mon Application Ruby</h1>
|
| 30 |
+
|
| 31 |
+
<h2>Testez l'API</h2>
|
| 32 |
+
|
| 33 |
+
<div>
|
| 34 |
+
<h3>Saluer quelqu'un</h3>
|
| 35 |
+
<input type="text" id="nameInput" placeholder="Votre nom" value="Monde">
|
| 36 |
+
<button onclick="greet()">Saluer</button>
|
| 37 |
+
<div id="greetResult" class="result"></div>
|
| 38 |
+
</div>
|
| 39 |
+
|
| 40 |
+
<div>
|
| 41 |
+
<h3>Créer un utilisateur</h3>
|
| 42 |
+
<input type="text" id="userName" placeholder="Nom">
|
| 43 |
+
<input type="email" id="userEmail" placeholder="Email">
|
| 44 |
+
<button onclick="createUser()">Créer</button>
|
| 45 |
+
<div id="userResult" class="result"></div>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
<div>
|
| 49 |
+
<h3>Santé de l'application</h3>
|
| 50 |
+
<button onclick="checkHealth()">Vérifier</button>
|
| 51 |
+
<div id="healthResult" class="result"></div>
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
<script>
|
| 56 |
+
async function greet() {
|
| 57 |
+
const name = document.getElementById('nameInput').value || 'Monde';
|
| 58 |
+
const response = await fetch(`/hello/${encodeURIComponent(name)}`);
|
| 59 |
+
const data = await response.json();
|
| 60 |
+
document.getElementById('greetResult').innerHTML = JSON.stringify(data, null, 2);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
async function createUser() {
|
| 64 |
+
const name = document.getElementById('userName').value;
|
| 65 |
+
const email = document.getElementById('userEmail').value;
|
| 66 |
+
|
| 67 |
+
const response = await fetch('/users', {
|
| 68 |
+
method: 'POST',
|
| 69 |
+
headers: { 'Content-Type': 'application/json' },
|
| 70 |
+
body: JSON.stringify({ name, email })
|
| 71 |
+
});
|
| 72 |
+
const data = await response.json();
|
| 73 |
+
document.getElementById('userResult').innerHTML = JSON.stringify(data, null, 2);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
async function checkHealth() {
|
| 77 |
+
const response = await fetch('/health');
|
| 78 |
+
const data = await response.json();
|
| 79 |
+
document.getElementById('healthResult').innerHTML = JSON.stringify(data, null, 2);
|
| 80 |
+
}
|
| 81 |
+
</script>
|
| 82 |
+
</body>
|
| 83 |
+
</html>
|
| 84 |
+
HTML
|
| 85 |
+
end
|
| 86 |
+
|
| 87 |
+
# API Routes
|
| 88 |
+
get "/hello/:name" do
|
| 89 |
+
content_type :json
|
| 90 |
+
{
|
| 91 |
+
message: "Bonjour #{params[:name]}!",
|
| 92 |
+
status: "success",
|
| 93 |
+
timestamp: Time.now.iso8601,
|
| 94 |
+
}.to_json
|
| 95 |
+
end
|
| 96 |
+
|
| 97 |
+
post "/users" do
|
| 98 |
+
content_type :json
|
| 99 |
+
data = JSON.parse(request.body.read)
|
| 100 |
+
|
| 101 |
+
{
|
| 102 |
+
message: "Utilisateur créé avec succès",
|
| 103 |
+
user: data,
|
| 104 |
+
id: rand(1000..9999),
|
| 105 |
+
created_at: Time.now.iso8601,
|
| 106 |
+
}.to_json
|
| 107 |
+
end
|
| 108 |
+
|
| 109 |
+
get "/health" do
|
| 110 |
+
content_type :json
|
| 111 |
+
{
|
| 112 |
+
status: "OK",
|
| 113 |
+
version: "1.0.0",
|
| 114 |
+
ruby_version: RUBY_VERSION,
|
| 115 |
+
environment: ENV["RACK_ENV"] || "development",
|
| 116 |
+
}.to_json
|
| 117 |
+
end
|
| 118 |
+
|
| 119 |
+
# Route pour les informations sur l'API
|
| 120 |
+
get "/api" do
|
| 121 |
+
content_type :json
|
| 122 |
+
{
|
| 123 |
+
endpoints: [
|
| 124 |
+
{ method: "GET", path: "/", description: "Interface web" },
|
| 125 |
+
{ method: "GET", path: "/hello/:name", description: "Salutation personnalisée" },
|
| 126 |
+
{ method: "POST", path: "/users", description: "Créer un utilisateur" },
|
| 127 |
+
{ method: "GET", path: "/health", description: 'Santé de l\'application' },
|
| 128 |
+
{ method: "GET", path: "/api", description: 'Documentation de l\'API' },
|
| 129 |
+
],
|
| 130 |
+
}.to_json
|
| 131 |
+
end
|
| 132 |
+
end
|
bin/server
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env ruby
|
| 2 |
+
# bin/server
|
| 3 |
+
require_relative '../app'
|
| 4 |
+
MonApp.run!
|
config.ru
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# config.ru
|
| 2 |
+
require "./app"
|
| 3 |
+
run MonApp
|