Hjgugugjhuhjggg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,30 @@
|
|
1 |
from flask import Flask, request, jsonify, render_template_string
|
2 |
from vllm import LLM, SamplingParams
|
3 |
from langchain_community.cache import GPTCache
|
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
|
|
|
|
|
|
|
|
7 |
modelos = {
|
8 |
-
"facebook/opt-125m": LLM(model="facebook/opt-125m"),
|
9 |
-
"llama-3.2-1B": LLM(model="Hjgugugjhuhjggg/llama-3.2-1B-spinquant-hf"),
|
10 |
-
"gpt2": LLM(model="gpt2")
|
11 |
}
|
12 |
|
|
|
13 |
caches = {
|
14 |
-
nombre: GPTCache(modelo, max_size=1000)
|
15 |
for nombre, modelo in modelos.items()
|
16 |
}
|
17 |
|
|
|
18 |
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
19 |
|
|
|
20 |
html_code_docs = """
|
21 |
<!DOCTYPE html>
|
22 |
<html>
|
@@ -63,6 +71,7 @@ html_code_docs = """
|
|
63 |
</html>
|
64 |
"""
|
65 |
|
|
|
66 |
html_code_chatbot = """
|
67 |
<!DOCTYPE html>
|
68 |
<html>
|
|
|
1 |
from flask import Flask, request, jsonify, render_template_string
|
2 |
from vllm import LLM, SamplingParams
|
3 |
from langchain_community.cache import GPTCache
|
4 |
+
import torch
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
8 |
+
# Verificar si hay una GPU disponible, si no usar la CPU
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
|
11 |
+
# Inicializar los modelos con el dispositivo adecuado (GPU o CPU)
|
12 |
modelos = {
|
13 |
+
"facebook/opt-125m": LLM(model="facebook/opt-125m", device=device),
|
14 |
+
"llama-3.2-1B": LLM(model="Hjgugugjhuhjggg/llama-3.2-1B-spinquant-hf", device=device),
|
15 |
+
"gpt2": LLM(model="gpt2", device=device)
|
16 |
}
|
17 |
|
18 |
+
# Configuraci贸n de cach茅 para los modelos
|
19 |
caches = {
|
20 |
+
nombre: GPTCache(modelo, max_size=1000)
|
21 |
for nombre, modelo in modelos.items()
|
22 |
}
|
23 |
|
24 |
+
# Par谩metros de muestreo para la generaci贸n de texto
|
25 |
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
26 |
|
27 |
+
# C贸digo HTML para la documentaci贸n de la API
|
28 |
html_code_docs = """
|
29 |
<!DOCTYPE html>
|
30 |
<html>
|
|
|
71 |
</html>
|
72 |
"""
|
73 |
|
74 |
+
# C贸digo HTML para la interfaz del chatbot
|
75 |
html_code_chatbot = """
|
76 |
<!DOCTYPE html>
|
77 |
<html>
|