Spaces:
Runtime error
Runtime error
Commit ·
204221f
1
Parent(s): 22bbea2
gas with interface
Browse files- app.py +12 -8
- templates/ask.html +81 -0
app.py
CHANGED
|
@@ -1,18 +1,22 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
pipe = pipeline("
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
-
|
| 9 |
|
| 10 |
@app.get('/')
|
| 11 |
def home():
|
| 12 |
return {"hello": "Bitfumes"}
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
@app.
|
| 16 |
-
def
|
| 17 |
-
result = pipe(prompt)
|
| 18 |
-
return result[0]
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
+
from fastapi.templating import Jinja2Templates
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
+
pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1")
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
+
templates = Jinja2Templates(directory="templates")
|
| 10 |
|
| 11 |
@app.get('/')
|
| 12 |
def home():
|
| 13 |
return {"hello": "Bitfumes"}
|
| 14 |
|
| 15 |
+
@app.get('/ask', response_class=HTMLResponse)
|
| 16 |
+
async def ask_form(request: Request):
|
| 17 |
+
return templates.TemplateResponse("ask.html", {"request": request})
|
| 18 |
|
| 19 |
+
@app.post('/ask')
|
| 20 |
+
async def generate(prompt: str):
|
| 21 |
+
result = pipe(prompt, max_length=100, num_return_sequences=1)
|
| 22 |
+
return {"generated_text": result[0]['generated_text']}
|
templates/ask.html
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Text Generation</title>
|
| 5 |
+
<style>
|
| 6 |
+
body {
|
| 7 |
+
font-family: Arial, sans-serif;
|
| 8 |
+
max-width: 800px;
|
| 9 |
+
margin: 0 auto;
|
| 10 |
+
padding: 20px;
|
| 11 |
+
}
|
| 12 |
+
.container {
|
| 13 |
+
background-color: #f5f5f5;
|
| 14 |
+
padding: 20px;
|
| 15 |
+
border-radius: 8px;
|
| 16 |
+
}
|
| 17 |
+
textarea {
|
| 18 |
+
width: 100%;
|
| 19 |
+
height: 150px;
|
| 20 |
+
margin-bottom: 10px;
|
| 21 |
+
padding: 10px;
|
| 22 |
+
border: 1px solid #ddd;
|
| 23 |
+
border-radius: 4px;
|
| 24 |
+
}
|
| 25 |
+
button {
|
| 26 |
+
background-color: #007bff;
|
| 27 |
+
color: white;
|
| 28 |
+
padding: 10px 20px;
|
| 29 |
+
border: none;
|
| 30 |
+
border-radius: 4px;
|
| 31 |
+
cursor: pointer;
|
| 32 |
+
}
|
| 33 |
+
button:hover {
|
| 34 |
+
background-color: #0056b3;
|
| 35 |
+
}
|
| 36 |
+
#result {
|
| 37 |
+
margin-top: 20px;
|
| 38 |
+
padding: 15px;
|
| 39 |
+
border: 1px solid #ddd;
|
| 40 |
+
border-radius: 4px;
|
| 41 |
+
display: none;
|
| 42 |
+
}
|
| 43 |
+
</style>
|
| 44 |
+
</head>
|
| 45 |
+
<body>
|
| 46 |
+
<div class="container">
|
| 47 |
+
<h1>Text Generation</h1>
|
| 48 |
+
<form id="generateForm">
|
| 49 |
+
<textarea id="prompt" name="prompt" placeholder="Enter your text here..."></textarea>
|
| 50 |
+
<button type="submit">Generate</button>
|
| 51 |
+
</form>
|
| 52 |
+
<div id="result"></div>
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
<script>
|
| 56 |
+
document.getElementById('generateForm').addEventListener('submit', async (e) => {
|
| 57 |
+
e.preventDefault();
|
| 58 |
+
const prompt = document.getElementById('prompt').value;
|
| 59 |
+
const resultDiv = document.getElementById('result');
|
| 60 |
+
|
| 61 |
+
try {
|
| 62 |
+
const response = await fetch('/ask', {
|
| 63 |
+
method: 'POST',
|
| 64 |
+
headers: {
|
| 65 |
+
'Content-Type': 'application/json',
|
| 66 |
+
},
|
| 67 |
+
body: JSON.stringify({ prompt: prompt })
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
const data = await response.json();
|
| 71 |
+
resultDiv.textContent = data.generated_text;
|
| 72 |
+
resultDiv.style.display = 'block';
|
| 73 |
+
} catch (error) {
|
| 74 |
+
console.error('Error:', error);
|
| 75 |
+
resultDiv.textContent = 'An error occurred while generating the text.';
|
| 76 |
+
resultDiv.style.display = 'block';
|
| 77 |
+
}
|
| 78 |
+
});
|
| 79 |
+
</script>
|
| 80 |
+
</body>
|
| 81 |
+
</html>
|