test2
Browse files- app.py +37 -3
- static/Makoto_anime.webp +0 -0
- static/makoto.jpg +0 -0
- static/ononoki.jpg +0 -0
- static/rias.jpg +0 -0
- static/ririsa.jpg +0 -0
- templates/chat.html +140 -0
- templates/listapersonajes.html +51 -0
app.py
CHANGED
@@ -1,7 +1,41 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from fastapi.responses import HTMLResponse
|
5 |
+
from fastapi.templating import Jinja2Templates
|
6 |
+
from fastapi import Request
|
7 |
+
from fastapi.staticfiles import StaticFiles
|
8 |
+
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
12 |
+
# Configura las plantillas Jinja2
|
13 |
+
templates = Jinja2Templates(directory="templates")
|
14 |
+
|
15 |
+
# Define el personaje
|
16 |
+
personaje = "rias"
|
17 |
+
|
18 |
+
# Monta la carpeta 'static' para servir archivos estáticos
|
19 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
20 |
+
|
21 |
+
# Ruta para mostrar los personajes
|
22 |
+
@app.get("/", response_class=HTMLResponse)
|
23 |
+
async def read_html(request: Request):
|
24 |
+
return templates.TemplateResponse("listapersonajes.html", {"request": request})
|
25 |
+
|
26 |
+
# Ruta dinámica para cada personaje
|
27 |
+
@app.get("/personajes/{personaje}", response_class=HTMLResponse)
|
28 |
+
async def personaje_detalle(request: Request, personaje: str):
|
29 |
+
# El contexto es el nombre de la imagen que se usará
|
30 |
+
context = {
|
31 |
+
"character_image": f"{personaje}.jpg" , # Asume que el nombre de la imagen es igual al personaje
|
32 |
+
"character_name": personaje.capitalize() # Nombre del personaje con la primera letra en mayúscula
|
33 |
+
|
34 |
+
}
|
35 |
+
return templates.TemplateResponse("chat.html", {"request": request, **context})
|
36 |
+
@app.get("/", response_class=HTMLResponse)
|
37 |
+
def read_html():
|
38 |
+
with open("templates/chat.html", "r") as f:
|
39 |
+
html_content = f.read()
|
40 |
+
return html_content
|
41 |
+
|
static/Makoto_anime.webp
ADDED
![]() |
static/makoto.jpg
ADDED
![]() |
static/ononoki.jpg
ADDED
![]() |
static/rias.jpg
ADDED
![]() |
static/ririsa.jpg
ADDED
![]() |
templates/chat.html
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Live Chat</title>
|
7 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
background: #F4F7FC;
|
11 |
+
font-family: 'Roboto', sans-serif;
|
12 |
+
margin: 0;
|
13 |
+
padding: 0;
|
14 |
+
display: flex;
|
15 |
+
justify-content: center;
|
16 |
+
align-items: center;
|
17 |
+
height: 100vh;
|
18 |
+
}
|
19 |
+
|
20 |
+
.chat-container {
|
21 |
+
width: 100%;
|
22 |
+
max-width: 900px;
|
23 |
+
height: 90vh;
|
24 |
+
background: #fff;
|
25 |
+
border-radius: 15px;
|
26 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
27 |
+
display: flex;
|
28 |
+
flex-direction: column;
|
29 |
+
}
|
30 |
+
|
31 |
+
.chat-header {
|
32 |
+
background: #04CB28;
|
33 |
+
border-radius: 15px 15px 0 0;
|
34 |
+
padding: 20px;
|
35 |
+
display: flex;
|
36 |
+
justify-content: space-between;
|
37 |
+
align-items: center;
|
38 |
+
color: #fff;
|
39 |
+
font-weight: bold;
|
40 |
+
}
|
41 |
+
|
42 |
+
.chat-bubble {
|
43 |
+
border-radius: 20px;
|
44 |
+
padding: 12px;
|
45 |
+
font-size: 14px;
|
46 |
+
background: #E2FFE8;
|
47 |
+
margin-bottom: 10px;
|
48 |
+
word-wrap: break-word;
|
49 |
+
}
|
50 |
+
|
51 |
+
.chat-bubble.bg-white {
|
52 |
+
background: #F8F9FA;
|
53 |
+
border: 1px solid #E7E7E9;
|
54 |
+
}
|
55 |
+
|
56 |
+
.message-container {
|
57 |
+
flex-grow: 1;
|
58 |
+
overflow-y: auto;
|
59 |
+
padding: 20px;
|
60 |
+
}
|
61 |
+
|
62 |
+
.message {
|
63 |
+
display: flex;
|
64 |
+
align-items: flex-start;
|
65 |
+
margin-bottom: 15px;
|
66 |
+
}
|
67 |
+
|
68 |
+
.message.right {
|
69 |
+
justify-content: flex-end;
|
70 |
+
}
|
71 |
+
|
72 |
+
.message.left {
|
73 |
+
justify-content: flex-start;
|
74 |
+
}
|
75 |
+
|
76 |
+
.message img {
|
77 |
+
border-radius: 50%;
|
78 |
+
width: 45px;
|
79 |
+
height: 45px;
|
80 |
+
margin-right: 10px;
|
81 |
+
}
|
82 |
+
|
83 |
+
.form-control {
|
84 |
+
width: 100%;
|
85 |
+
border-radius: 12px;
|
86 |
+
border: 1px solid #F0F0F0;
|
87 |
+
padding: 12px;
|
88 |
+
font-size: 14px;
|
89 |
+
margin-top: 10px;
|
90 |
+
resize: none;
|
91 |
+
}
|
92 |
+
|
93 |
+
.form-control:focus {
|
94 |
+
border-color: #04CB28;
|
95 |
+
box-shadow: none;
|
96 |
+
}
|
97 |
+
|
98 |
+
.form-control::placeholder {
|
99 |
+
font-size: 14px;
|
100 |
+
color: #C4C4C4;
|
101 |
+
}
|
102 |
+
</style>
|
103 |
+
</head>
|
104 |
+
<body>
|
105 |
+
<div class="chat-container">
|
106 |
+
<div class="chat-header">
|
107 |
+
<span>Live Chat - {{ character_name }}</span>
|
108 |
+
</div>
|
109 |
+
|
110 |
+
<div class="message-container">
|
111 |
+
<!-- Mensaje de usuario con imagen dinámica -->
|
112 |
+
<div class="message left">
|
113 |
+
<img src="/static/{{ character_image }}" alt="User Profile" id="user-img">
|
114 |
+
<div class="chat-bubble">
|
115 |
+
<span id="user-name">Usuario</span>: ¡Hola, soy {{ character_name }} Gracias por visitar mi chat.
|
116 |
+
</div>
|
117 |
+
</div>
|
118 |
+
<!-- Mensaje de bot con imagen dinámica -->
|
119 |
+
<div class="message right">
|
120 |
+
<div class="chat-bubble bg-white">
|
121 |
+
<span class="text-muted">¿Cómo estás?</span>
|
122 |
+
</div>
|
123 |
+
<img src="/static/Makoto_anime.webp" alt="Bot Profile" id="bot-img">
|
124 |
+
</div>
|
125 |
+
</div>
|
126 |
+
|
127 |
+
<div class="form-group px-3">
|
128 |
+
<textarea class="form-control" rows="3" placeholder="Escribe tu mensaje..."></textarea>
|
129 |
+
</div>
|
130 |
+
</div>
|
131 |
+
|
132 |
+
<script>
|
133 |
+
// Configurar nombre dinámico para el usuario y el bot
|
134 |
+
document.getElementById('user-name').textContent = "{{ character_name }}";
|
135 |
+
document.getElementById('bot-img').src = "/static/Makoto_anime.webp"; // Cambia la imagen del bot
|
136 |
+
document.getElementById('user-img').src = "/static/{{ character_image }}"; // Cambia la imagen del usuario </script>
|
137 |
+
<!-- Bootstrap JS (opcional, para funcionalidades como botones y otros componentes interactivos) -->
|
138 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
139 |
+
</body>
|
140 |
+
</html>
|
templates/listapersonajes.html
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Lista de Personajes</title>
|
7 |
+
<!-- Bootstrap CSS -->
|
8 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
9 |
+
</head>
|
10 |
+
<body class="bg-light">
|
11 |
+
<div class="container mt-5">
|
12 |
+
<h1 class="text-center">Lista de Personajes</h1>
|
13 |
+
<div class="row justify-content-center mt-4">
|
14 |
+
<!-- Card 1: Ririsa Amano -->
|
15 |
+
<div class="col-md-4">
|
16 |
+
<div class="card">
|
17 |
+
<img src="/static/ririsa.jpg" class="card-img-top" alt="Ririsa Amano">
|
18 |
+
<div class="card-body text-center">
|
19 |
+
<h5 class="card-title">Ririsa Amano</h5>
|
20 |
+
<a href="/personajes/ririsa" class="btn btn-primary">Ver personaje</a>
|
21 |
+
</div>
|
22 |
+
</div>
|
23 |
+
</div>
|
24 |
+
<!-- Card 2: Rias Gremory -->
|
25 |
+
<div class="col-md-4">
|
26 |
+
<div class="card">
|
27 |
+
<img src="/static/rias.jpg" class="card-img-top" alt="Rias Gremory">
|
28 |
+
<div class="card-body text-center">
|
29 |
+
<h5 class="card-title">Rias Gremory</h5>
|
30 |
+
<a href="/personajes/rias" class="btn btn-primary">Ver personaje</a>
|
31 |
+
</div>
|
32 |
+
</div>
|
33 |
+
</div>
|
34 |
+
<!-- Card 3: Ononoki Yotsugi -->
|
35 |
+
<div class="col-md-4">
|
36 |
+
<div class="card">
|
37 |
+
<img src="/static/ononoki.jpg" class="card-img-top" alt="Ononoki Yotsugi">
|
38 |
+
<div class="card-body text-center">
|
39 |
+
<h5 class="card-title">Ononoki Yotsugi</h5>
|
40 |
+
<a href="/personajes/ononoki" class="btn btn-primary">Ver personaje</a>
|
41 |
+
</div>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
</div>
|
45 |
+
</div>
|
46 |
+
|
47 |
+
<!-- Bootstrap JS -->
|
48 |
+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
|
49 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
|
50 |
+
</body>
|
51 |
+
</html>
|