Download app.rb from Rovatiana/test_ruby: direct link, hf CLI and curl.
- Browser
- Download file 2.82 kB
-
https://huggingface.co/spaces/Rovatiana/test_ruby/resolve/main/app.rb
- Command line
-
hf download hf://spaces/Rovatiana/test_ruby/app.rb
-
curl -L -o app.rb https://huggingface.co/spaces/Rovatiana/test_ruby/resolve/main/app.rb
2.82 kB
| # app.rb | |
| begin | |
| require "bundler/setup" | |
| rescue Bundler::PermissionError => e | |
| # Fallback: charger les gems manuellement si Bundler échoue | |
| require "sinatra" | |
| require "json" | |
| require "puma" | |
| rescue LoadError => e | |
| puts "Bundler non disponible, chargement manuel des gems" | |
| require "sinatra" | |
| require "json" | |
| end | |
| class MonApp < Sinatra::Base | |
| configure do | |
| set :port, 7860 | |
| set :bind, "0.0.0.0" | |
| set :server, :puma | |
| end | |
| # ... le reste de votre code reste inchangé ... | |
| get "/" do | |
| content_type :html | |
| <<~HTML | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Mon Application Ruby</title> | |
| <style> | |
| body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; } | |
| .container { background: #f5f5f5; padding: 20px; border-radius: 10px; } | |
| input, button { padding: 10px; margin: 5px; } | |
| .result { background: white; padding: 15px; border-radius: 5px; margin-top: 10px; } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>🚀 Mon Application Ruby</h1> | |
| <p>Application démarrée avec succès!</p> | |
| <h2>Testez l'API</h2> | |
| <div> | |
| <h3>Saluer quelqu'un</h3> | |
| <input type="text" id="nameInput" placeholder="Votre nom" value="Monde"> | |
| <button onclick="greet()">Saluer</button> | |
| <div id="greetResult" class="result"></div> | |
| </div> | |
| <div> | |
| <h3>Santé de l'application</h3> | |
| <button onclick="checkHealth()">Vérifier</button> | |
| <div id="healthResult" class="result"></div> | |
| </div> | |
| </div> | |
| <script> | |
| async function greet() { | |
| const name = document.getElementById('nameInput').value || 'Monde'; | |
| const response = await fetch(`/hello/${encodeURIComponent(name)}`); | |
| const data = await response.json(); | |
| document.getElementById('greetResult').innerHTML = JSON.stringify(data, null, 2); | |
| } | |
| async function checkHealth() { | |
| const response = await fetch('/health'); | |
| const data = await response.json(); | |
| document.getElementById('healthResult').innerHTML = JSON.stringify(data, null, 2); | |
| } | |
| </script> | |
| </body> | |
| </html> | |
| HTML | |
| end | |
| get "/hello/:name" do | |
| content_type :json | |
| { | |
| message: "Bonjour #{params[:name]}!", | |
| status: "success", | |
| timestamp: Time.now.iso8601, | |
| }.to_json | |
| end | |
| get "/health" do | |
| content_type :json | |
| { | |
| status: "OK", | |
| version: "1.0.0", | |
| ruby_version: RUBY_VERSION, | |
| }.to_json | |
| end | |
| end | |