Spaces:
Sleeping
Sleeping
Initial Commit
Browse files- Dockerfile +20 -0
- README.md +29 -11
- app/__init__.py +0 -0
- app/html/index.html +132 -0
- app/main.py +34 -0
- requirements.txt +5 -0
Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.11
|
| 3 |
+
ENV PYTHONUNBUFFERED 1
|
| 4 |
+
#
|
| 5 |
+
RUN mkdir ./.cache
|
| 6 |
+
RUN mkdir /code
|
| 7 |
+
WORKDIR /code
|
| 8 |
+
#
|
| 9 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 10 |
+
#
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 12 |
+
EXPOSE 7860
|
| 13 |
+
#
|
| 14 |
+
COPY ./app /code/app
|
| 15 |
+
RUN useradd -m -u 1000 user
|
| 16 |
+
USER user
|
| 17 |
+
ENV HOME=/home/user \
|
| 18 |
+
PATH=/home/user/.local/bin:$PATH
|
| 19 |
+
#
|
| 20 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,11 +1,29 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Practice API
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned:
|
| 8 |
-
license:
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Practice API
|
| 3 |
+
emoji: 🌊
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: true
|
| 8 |
+
license: mit
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
A tool to host your own webpages for free using Huggingface's docker spaces
|
| 14 |
+
|
| 15 |
+
[](https://choosealicense.com/licenses/mit/)
|
| 16 |
+
|
| 17 |
+
## Usage
|
| 18 |
+
|
| 19 |
+
1. First clone the freehost docker space found [here](https://huggingface.co/spaces/Sankie005/Freehost/tree/main)
|
| 20 |
+
|
| 21 |
+
2. Change the files inside app->html be sure to name your main landing page "index.html"
|
| 22 |
+
|
| 23 |
+
3. Run the dockerspace and watch your project run at "https://_huggingfaceusername_-_repositoryname_.hf.space"
|
| 24 |
+
Eg: This Space will run at:
|
| 25 |
+
https://sankie005-freehost.hf.space/
|
| 26 |
+
|
| 27 |
+
## Authors
|
| 28 |
+
|
| 29 |
+
- [Sankritya Anand Rai](https://www.github.com/sankie005)
|
app/__init__.py
ADDED
|
File without changes
|
app/html/index.html
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=Cabin:wght@600&display=swap" rel="stylesheet">
|
| 10 |
+
<title >Practice API</title>
|
| 11 |
+
<style>
|
| 12 |
+
body {
|
| 13 |
+
font-family: 'Cabin', sans-serif;
|
| 14 |
+
margin: 0;
|
| 15 |
+
padding: 0;
|
| 16 |
+
background: rgb(191,197,209);
|
| 17 |
+
background: linear-gradient(90deg, rgba(191,197,209,1) 11%, rgba(76,209,238,1) 36%, rgba(29,95,248,1) 75%);
|
| 18 |
+
color: #2c3e50;
|
| 19 |
+
}
|
| 20 |
+
header {
|
| 21 |
+
text-align: center;
|
| 22 |
+
padding: 10px;
|
| 23 |
+
background: rgb(191,197,209);
|
| 24 |
+
background: linear-gradient(90deg, rgba(191,197,209,1) 11%, rgba(76,209,238,1) 36%, rgba(29,95,248,1) 75%);
|
| 25 |
+
color: #fff;
|
| 26 |
+
border-bottom-left-radius: 20px;
|
| 27 |
+
border-bottom-right-radius: 10px;
|
| 28 |
+
}
|
| 29 |
+
section {
|
| 30 |
+
max-width: 800px;
|
| 31 |
+
margin: 20px auto;
|
| 32 |
+
padding: 20px;
|
| 33 |
+
background-color: #fff;
|
| 34 |
+
border: 1px solid #bdc3c7;
|
| 35 |
+
border-radius: 10px;
|
| 36 |
+
}
|
| 37 |
+
title {
|
| 38 |
+
color: white;
|
| 39 |
+
font-size: xx-large;
|
| 40 |
+
}
|
| 41 |
+
h1 {
|
| 42 |
+
color: #1807aa;
|
| 43 |
+
font-family: 'Cabin', sans-serif;
|
| 44 |
+
font-size: 2em; /* Increased font size */
|
| 45 |
+
}
|
| 46 |
+
h2 {
|
| 47 |
+
color: black;
|
| 48 |
+
}
|
| 49 |
+
h3 {
|
| 50 |
+
color: white;
|
| 51 |
+
font-size: 68px;
|
| 52 |
+
padding: auto;
|
| 53 |
+
font-weight: bolder;
|
| 54 |
+
font-family: 'Cabin', sans-serif;
|
| 55 |
+
}
|
| 56 |
+
#navigateButton {
|
| 57 |
+
display: inline-block;
|
| 58 |
+
padding: 10px 20px;
|
| 59 |
+
margin-top: 10px;
|
| 60 |
+
background-color: black;
|
| 61 |
+
color: #fff;
|
| 62 |
+
text-decoration: none;
|
| 63 |
+
border-radius: 5px;
|
| 64 |
+
transition: background-color 0.3s;
|
| 65 |
+
}
|
| 66 |
+
#navigateButton:hover {
|
| 67 |
+
background-color: #2980b9;
|
| 68 |
+
color:white;
|
| 69 |
+
}
|
| 70 |
+
footer {
|
| 71 |
+
text-align: center;
|
| 72 |
+
padding: 10px;
|
| 73 |
+
background: rgb(191,197,209);
|
| 74 |
+
background: linear-gradient(90deg, rgba(191,197,209,1) 11%, rgba(76,209,238,1) 36%, rgba(29,95,248,1) 75%);
|
| 75 |
+
color: #fff;
|
| 76 |
+
border-top-left-radius: 10px;
|
| 77 |
+
border-top-right-radius: 10px;
|
| 78 |
+
}
|
| 79 |
+
/* Added the following CSS rule to make content bold */
|
| 80 |
+
section p {
|
| 81 |
+
font-weight: bold;
|
| 82 |
+
font-family: 'Rubik', sans-serif;
|
| 83 |
+
}
|
| 84 |
+
</style>
|
| 85 |
+
</head>
|
| 86 |
+
<body>
|
| 87 |
+
<header>
|
| 88 |
+
<h3>Practice API</h3>
|
| 89 |
+
<h3 style="font-size: medium;">A fun practice API for untangl</h3>
|
| 90 |
+
</header>
|
| 91 |
+
|
| 92 |
+
<section>
|
| 93 |
+
<h2>About</h2>
|
| 94 |
+
<p>
|
| 95 |
+
<strong>Contains some simple functions!</strong>
|
| 96 |
+
</p>
|
| 97 |
+
</section>
|
| 98 |
+
|
| 99 |
+
<section>
|
| 100 |
+
<h2>Documentation</h2>
|
| 101 |
+
<p>
|
| 102 |
+
<strong>To look at the Docs page click the button below
|
| 103 |
+
</p>
|
| 104 |
+
<p>
|
| 105 |
+
<a id="navigateButton">API Documentation</a>
|
| 106 |
+
<script>
|
| 107 |
+
document.getElementById('navigateButton').addEventListener('click', function() {
|
| 108 |
+
// Get the current URL
|
| 109 |
+
var currentUrl = window.location.href;
|
| 110 |
+
|
| 111 |
+
// Append "/docs" to the current URL
|
| 112 |
+
var newUrl = currentUrl + 'docs';
|
| 113 |
+
|
| 114 |
+
// Navigate to the new URL
|
| 115 |
+
window.location.href = newUrl;
|
| 116 |
+
});
|
| 117 |
+
</script>
|
| 118 |
+
</p>
|
| 119 |
+
</section>
|
| 120 |
+
<section>
|
| 121 |
+
<h2> Crediting and usage</h2>
|
| 122 |
+
<p>
|
| 123 |
+
<strong> If you wish to use this in your own projects and credit me then feel free to link my <a href="https://github.com/Sankie005">Github</a> or <a href="https://linkedin.com/in/sankritya-rai-002a40261/">Linkedin</a> in your website footer
|
| 124 |
+
</p>
|
| 125 |
+
|
| 126 |
+
</section>
|
| 127 |
+
|
| 128 |
+
<footer>
|
| 129 |
+
<p>© 2024 Sankie005 on github</p>
|
| 130 |
+
</footer>
|
| 131 |
+
</body>
|
| 132 |
+
</html>
|
app/main.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException,APIRouter,Request
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from starlette.responses import FileResponse
|
| 5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
|
| 8 |
+
from pydantic import BaseModel
|
| 9 |
+
|
| 10 |
+
class UserRequest(BaseModel):
|
| 11 |
+
text: str
|
| 12 |
+
length: int
|
| 13 |
+
app = FastAPI()
|
| 14 |
+
origins = ["*"]
|
| 15 |
+
app.add_middleware(
|
| 16 |
+
CORSMiddleware,
|
| 17 |
+
allow_origins=origins,
|
| 18 |
+
)
|
| 19 |
+
app.mount("/files/", StaticFiles(directory='../code'), name="index")
|
| 20 |
+
@app.get("/")
|
| 21 |
+
async def read_index():
|
| 22 |
+
return FileResponse('app/html/index.html')
|
| 23 |
+
@app.post("/Summarizer/")
|
| 24 |
+
async def get_summary(post: UserRequest):
|
| 25 |
+
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
| 26 |
+
query=str(post.text)
|
| 27 |
+
query_clean=""+query
|
| 28 |
+
summary = summarizer(query_clean, max_length=post.length, min_length=10, do_sample=False)
|
| 29 |
+
return (summary[0]['summary_text'])
|
| 30 |
+
@app.post("/Freedom Units/")
|
| 31 |
+
async def converter(temperature:float):
|
| 32 |
+
return (temperature*(9/5))+32
|
| 33 |
+
|
| 34 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
requests
|
| 4 |
+
transformers
|
| 5 |
+
torch
|