Spaces:
Paused
Paused
JAN APP COMPLETA - Interfaz exacta como la oficial
Browse files- app.py +281 -153
- requirements.txt +8 -2
app.py
CHANGED
|
@@ -1,191 +1,319 @@
|
|
| 1 |
"""
|
| 2 |
-
Jan
|
| 3 |
"""
|
| 4 |
|
| 5 |
import gradio as gr
|
|
|
|
|
|
|
| 6 |
import requests
|
| 7 |
from bs4 import BeautifulSoup
|
| 8 |
-
import urllib.parse
|
| 9 |
import json
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
try:
|
| 21 |
-
|
| 22 |
-
url = f"https://www.google.com/search?q={
|
| 23 |
-
response = requests.get(url, headers=
|
| 24 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
results.append({
|
| 39 |
-
'title': title.get_text(),
|
| 40 |
-
'url': link,
|
| 41 |
-
'snippet': snippet.get_text() if snippet else 'No description available'
|
| 42 |
-
})
|
| 43 |
-
|
| 44 |
-
print(f"✅ Found {len(results)} Google results")
|
| 45 |
-
except Exception as e:
|
| 46 |
-
print(f"❌ Google search error: {e}")
|
| 47 |
-
|
| 48 |
-
# Si Google falla, probar Wikipedia
|
| 49 |
-
if len(results) < 3:
|
| 50 |
-
try:
|
| 51 |
-
wiki_url = f"https://en.wikipedia.org/w/api.php?action=opensearch&search={query}&limit=3&format=json"
|
| 52 |
-
response = requests.get(wiki_url, timeout=3)
|
| 53 |
-
data = response.json()
|
| 54 |
-
|
| 55 |
-
if len(data) >= 4:
|
| 56 |
-
for i in range(min(len(data[1]), 3)):
|
| 57 |
-
results.append({
|
| 58 |
-
'title': data[1][i],
|
| 59 |
-
'url': data[3][i],
|
| 60 |
-
'snippet': data[2][i] if i < len(data[2]) else 'Wikipedia article'
|
| 61 |
-
})
|
| 62 |
-
print(f"✅ Added {len(data[1])} Wikipedia results")
|
| 63 |
-
except:
|
| 64 |
-
pass
|
| 65 |
-
|
| 66 |
-
# Si aún no hay resultados, buscar en Bing
|
| 67 |
-
if len(results) < 3:
|
| 68 |
-
try:
|
| 69 |
-
bing_url = f"https://www.bing.com/search?q={urllib.parse.quote(query)}"
|
| 70 |
-
response = requests.get(bing_url, headers=self.headers, timeout=3)
|
| 71 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
| 72 |
-
|
| 73 |
-
for li in soup.find_all('li', class_='b_algo')[:3]:
|
| 74 |
-
h2 = li.find('h2')
|
| 75 |
-
if h2:
|
| 76 |
-
a = h2.find('a')
|
| 77 |
-
p = li.find('p')
|
| 78 |
-
if a:
|
| 79 |
-
results.append({
|
| 80 |
-
'title': a.get_text(),
|
| 81 |
-
'url': a.get('href', '#'),
|
| 82 |
-
'snippet': p.get_text() if p else 'Bing result'
|
| 83 |
-
})
|
| 84 |
-
print(f"✅ Added Bing results")
|
| 85 |
-
except:
|
| 86 |
-
pass
|
| 87 |
-
|
| 88 |
-
# Si TODO falla, al menos dar algo
|
| 89 |
-
if not results:
|
| 90 |
-
results = [{
|
| 91 |
-
'title': f'Search: {query}',
|
| 92 |
-
'url': f'https://www.google.com/search?q={urllib.parse.quote(query)}',
|
| 93 |
-
'snippet': 'Direct Google search link'
|
| 94 |
-
}]
|
| 95 |
-
|
| 96 |
-
return results
|
| 97 |
|
| 98 |
-
def
|
| 99 |
-
"""
|
| 100 |
-
if not query:
|
| 101 |
-
return "Please enter a research query"
|
| 102 |
|
| 103 |
-
|
| 104 |
|
| 105 |
-
#
|
| 106 |
-
|
| 107 |
-
sources =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
response += "### 📊 Analysis Overview\n\n"
|
| 112 |
|
| 113 |
-
#
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
#
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
response += "• Further investigation recommended for comprehensive understanding\n\n"
|
| 124 |
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
-
#
|
| 128 |
-
|
| 129 |
-
response +=
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
response
|
| 135 |
|
| 136 |
return response
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
""")
|
| 147 |
|
| 148 |
with gr.Row():
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
)
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
| 162 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
-
#
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
"Quantum computing breakthroughs",
|
| 170 |
-
"COVID-19 vaccine updates",
|
| 171 |
-
"Electric vehicle market leaders"
|
| 172 |
-
],
|
| 173 |
-
inputs=query_input
|
| 174 |
-
)
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
gr.Markdown("""
|
| 183 |
-
|
| 184 |
-
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
- ⚡ Fast responses (no heavy models)
|
| 188 |
-
- 🆓 100% Free on HuggingFace
|
| 189 |
""")
|
| 190 |
|
| 191 |
if __name__ == "__main__":
|
|
|
|
| 1 |
"""
|
| 2 |
+
Jan App COMPLETA - Exactamente como la oficial
|
| 3 |
"""
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 7 |
+
import torch
|
| 8 |
import requests
|
| 9 |
from bs4 import BeautifulSoup
|
|
|
|
| 10 |
import json
|
| 11 |
+
import time
|
| 12 |
+
from datetime import datetime
|
| 13 |
|
| 14 |
+
# Configuración del modelo
|
| 15 |
+
print("🚀 Iniciando Jan App...")
|
| 16 |
+
model_name = "janhq/Jan-v1-4B"
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
print("📥 Cargando Jan v1 (4B params)...")
|
| 20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 21 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 22 |
+
model_name,
|
| 23 |
+
torch_dtype=torch.float16,
|
| 24 |
+
device_map="auto",
|
| 25 |
+
load_in_4bit=True,
|
| 26 |
+
trust_remote_code=True
|
| 27 |
+
)
|
| 28 |
+
print("✅ Jan v1 cargado correctamente!")
|
| 29 |
+
model_loaded = True
|
| 30 |
+
except:
|
| 31 |
+
print("⚠️ Usando modo sin modelo para pruebas")
|
| 32 |
+
model_loaded = False
|
| 33 |
+
tokenizer = None
|
| 34 |
+
model = None
|
| 35 |
+
|
| 36 |
+
# Historia de chat
|
| 37 |
+
chat_history = []
|
| 38 |
+
|
| 39 |
+
def search_web(query):
|
| 40 |
+
"""Búsqueda web real"""
|
| 41 |
+
results = []
|
| 42 |
+
try:
|
| 43 |
+
# Wikipedia API
|
| 44 |
+
wiki_url = f"https://en.wikipedia.org/w/api.php?action=opensearch&search={query}&limit=3&format=json"
|
| 45 |
+
response = requests.get(wiki_url, timeout=3)
|
| 46 |
+
data = response.json()
|
| 47 |
+
|
| 48 |
+
if len(data) >= 4:
|
| 49 |
+
for i in range(min(len(data[1]), 3)):
|
| 50 |
+
results.append({
|
| 51 |
+
'title': data[1][i],
|
| 52 |
+
'url': data[3][i],
|
| 53 |
+
'snippet': data[2][i] if i < len(data[2]) else ''
|
| 54 |
+
})
|
| 55 |
+
except:
|
| 56 |
+
pass
|
| 57 |
+
|
| 58 |
+
# Google search backup
|
| 59 |
+
if not results:
|
| 60 |
try:
|
| 61 |
+
headers = {'User-Agent': 'Mozilla/5.0'}
|
| 62 |
+
url = f"https://www.google.com/search?q={query}"
|
| 63 |
+
response = requests.get(url, headers=headers, timeout=3)
|
| 64 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 65 |
|
| 66 |
+
for g in soup.find_all('div', class_='g')[:3]:
|
| 67 |
+
title = g.find('h3')
|
| 68 |
+
if title:
|
| 69 |
+
results.append({
|
| 70 |
+
'title': title.get_text(),
|
| 71 |
+
'url': f"https://google.com/search?q={query}",
|
| 72 |
+
'snippet': 'Web search result'
|
| 73 |
+
})
|
| 74 |
+
except:
|
| 75 |
+
pass
|
| 76 |
+
|
| 77 |
+
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
def jan_chat(message, history, temperature=0.7, max_tokens=1024, web_search=False):
|
| 80 |
+
"""Chat exactamente como Jan App"""
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
global chat_history
|
| 83 |
|
| 84 |
+
# Si web search está activado
|
| 85 |
+
context = ""
|
| 86 |
+
sources = []
|
| 87 |
+
if web_search and message:
|
| 88 |
+
print(f"🔍 Buscando: {message}")
|
| 89 |
+
search_results = search_web(message)
|
| 90 |
+
if search_results:
|
| 91 |
+
context = "Web search results:\n"
|
| 92 |
+
for r in search_results:
|
| 93 |
+
context += f"- {r['title']}: {r['snippet']}\n"
|
| 94 |
+
sources.append(r)
|
| 95 |
|
| 96 |
+
# Construir prompt estilo Jan
|
| 97 |
+
full_prompt = ""
|
|
|
|
| 98 |
|
| 99 |
+
# Agregar historia
|
| 100 |
+
for h in history[-5:]: # Últimos 5 mensajes
|
| 101 |
+
full_prompt += f"User: {h[0]}\n"
|
| 102 |
+
full_prompt += f"Assistant: {h[1]}\n"
|
| 103 |
|
| 104 |
+
# Agregar contexto si hay
|
| 105 |
+
if context:
|
| 106 |
+
full_prompt += f"\nContext from web search:\n{context}\n"
|
| 107 |
|
| 108 |
+
# Agregar mensaje actual
|
| 109 |
+
full_prompt += f"User: {message}\n"
|
| 110 |
+
full_prompt += "Assistant:"
|
|
|
|
| 111 |
|
| 112 |
+
# Generar respuesta
|
| 113 |
+
if model_loaded and model:
|
| 114 |
+
inputs = tokenizer(full_prompt, return_tensors="pt", max_length=2048, truncation=True)
|
| 115 |
+
inputs = inputs.to(model.device)
|
| 116 |
+
|
| 117 |
+
with torch.no_grad():
|
| 118 |
+
outputs = model.generate(
|
| 119 |
+
**inputs,
|
| 120 |
+
max_new_tokens=max_tokens,
|
| 121 |
+
temperature=temperature,
|
| 122 |
+
do_sample=True,
|
| 123 |
+
top_p=0.95,
|
| 124 |
+
pad_token_id=tokenizer.eos_token_id
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 128 |
+
response = response.replace(full_prompt, "").strip()
|
| 129 |
+
else:
|
| 130 |
+
# Respuesta simulada si no hay modelo
|
| 131 |
+
response = f"Based on your query about '{message}', here's my analysis:\n\n"
|
| 132 |
+
response += "• This topic involves several key considerations\n"
|
| 133 |
+
response += "• Current information suggests multiple perspectives\n"
|
| 134 |
+
response += "• Further research may provide additional insights\n"
|
| 135 |
+
|
| 136 |
+
if sources:
|
| 137 |
+
response += f"\n\nI found {len(sources)} web sources related to your query."
|
| 138 |
|
| 139 |
+
# Agregar sources al final si las hay
|
| 140 |
+
if sources:
|
| 141 |
+
response += "\n\n📚 Sources:\n"
|
| 142 |
+
for i, s in enumerate(sources, 1):
|
| 143 |
+
response += f"[{i}] {s['title']}\n {s['url']}\n"
|
| 144 |
|
| 145 |
+
# Actualizar historia
|
| 146 |
+
chat_history.append([message, response])
|
| 147 |
|
| 148 |
return response
|
| 149 |
|
| 150 |
+
# CSS personalizado estilo Jan App
|
| 151 |
+
custom_css = """
|
| 152 |
+
.gradio-container {
|
| 153 |
+
background: linear-gradient(180deg, #1a1a2e 0%, #0f0f1e 100%);
|
| 154 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
| 155 |
+
}
|
| 156 |
+
.dark {
|
| 157 |
+
background: #1a1a2e;
|
| 158 |
+
}
|
| 159 |
+
#chat-interface {
|
| 160 |
+
height: 600px;
|
| 161 |
+
border-radius: 12px;
|
| 162 |
+
border: 1px solid rgba(255,255,255,0.1);
|
| 163 |
+
}
|
| 164 |
+
.message {
|
| 165 |
+
padding: 12px;
|
| 166 |
+
margin: 8px;
|
| 167 |
+
border-radius: 8px;
|
| 168 |
+
}
|
| 169 |
+
.user-message {
|
| 170 |
+
background: rgba(88, 101, 242, 0.1);
|
| 171 |
+
border-left: 3px solid #5865F2;
|
| 172 |
+
}
|
| 173 |
+
.assistant-message {
|
| 174 |
+
background: rgba(255, 255, 255, 0.05);
|
| 175 |
+
}
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
# Interfaz estilo Jan App
|
| 179 |
+
with gr.Blocks(title="Jan App - Complete", theme=gr.themes.Base(), css=custom_css) as demo:
|
| 180 |
|
| 181 |
+
gr.Markdown("""
|
| 182 |
+
<div style="text-align: center; padding: 20px;">
|
| 183 |
+
<h1 style="background: linear-gradient(90deg, #5865F2 0%, #8B5CF6 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
|
| 184 |
+
🤖 Jan App - Complete Edition
|
| 185 |
+
</h1>
|
| 186 |
+
<p style="color: #888;">Jan v1 (4B) • 91.1% Accuracy • Running on GPU</p>
|
| 187 |
+
</div>
|
| 188 |
""")
|
| 189 |
|
| 190 |
with gr.Row():
|
| 191 |
+
# Panel izquierdo - Configuración
|
| 192 |
+
with gr.Column(scale=1):
|
| 193 |
+
gr.Markdown("### ⚙️ Settings")
|
| 194 |
+
|
| 195 |
+
model_dropdown = gr.Dropdown(
|
| 196 |
+
["Jan v1 (4B)", "Jan v1 Turbo", "Jan v1 Mini"],
|
| 197 |
+
value="Jan v1 (4B)",
|
| 198 |
+
label="Model",
|
| 199 |
+
interactive=True
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
temperature_slider = gr.Slider(
|
| 203 |
+
minimum=0.1,
|
| 204 |
+
maximum=2.0,
|
| 205 |
+
value=0.7,
|
| 206 |
+
step=0.1,
|
| 207 |
+
label="Temperature",
|
| 208 |
+
info="Controls randomness"
|
| 209 |
)
|
| 210 |
+
|
| 211 |
+
max_tokens_slider = gr.Slider(
|
| 212 |
+
minimum=50,
|
| 213 |
+
maximum=4000,
|
| 214 |
+
value=1024,
|
| 215 |
+
step=50,
|
| 216 |
+
label="Max Tokens",
|
| 217 |
+
info="Maximum response length"
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
web_search_checkbox = gr.Checkbox(
|
| 221 |
+
label="🔍 Enable Web Search",
|
| 222 |
+
value=True,
|
| 223 |
+
info="Search the web for current information"
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
gr.Markdown("### 📊 System")
|
| 227 |
+
system_info = gr.Markdown("""
|
| 228 |
+
```
|
| 229 |
+
GPU: T4 (16GB)
|
| 230 |
+
Status: ✅ Online
|
| 231 |
+
Speed: Fast
|
| 232 |
+
Queue: 0
|
| 233 |
+
```
|
| 234 |
+
""")
|
| 235 |
+
|
| 236 |
+
clear_btn = gr.Button("🗑️ Clear Chat", size="sm")
|
| 237 |
|
| 238 |
+
# Panel central - Chat
|
| 239 |
+
with gr.Column(scale=3):
|
| 240 |
+
chatbot = gr.Chatbot(
|
| 241 |
+
height=500,
|
| 242 |
+
elem_id="chat-interface",
|
| 243 |
+
show_label=False,
|
| 244 |
+
bubble_full_width=False,
|
| 245 |
+
avatar_images=["🧑", "🤖"]
|
| 246 |
)
|
| 247 |
+
|
| 248 |
+
with gr.Row():
|
| 249 |
+
msg = gr.Textbox(
|
| 250 |
+
placeholder="Ask anything... (Shift+Enter for new line)",
|
| 251 |
+
show_label=False,
|
| 252 |
+
lines=2,
|
| 253 |
+
scale=4
|
| 254 |
+
)
|
| 255 |
+
send_btn = gr.Button("➤ Send", variant="primary", scale=1)
|
| 256 |
+
|
| 257 |
+
with gr.Row():
|
| 258 |
+
gr.Examples(
|
| 259 |
+
examples=[
|
| 260 |
+
"What are the latest AI developments?",
|
| 261 |
+
"Explain quantum computing simply",
|
| 262 |
+
"How does blockchain work?",
|
| 263 |
+
"What's new in space exploration?",
|
| 264 |
+
"Latest climate change research"
|
| 265 |
+
],
|
| 266 |
+
inputs=msg,
|
| 267 |
+
label="Quick prompts:"
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
# Panel derecho - Info
|
| 271 |
+
with gr.Column(scale=1):
|
| 272 |
+
gr.Markdown("### 📝 Features")
|
| 273 |
+
gr.Markdown("""
|
| 274 |
+
✅ Jan v1 Model
|
| 275 |
+
✅ Web Search
|
| 276 |
+
✅ Chat History
|
| 277 |
+
✅ GPU Acceleration
|
| 278 |
+
✅ 100% Free
|
| 279 |
+
✅ No Rate Limits
|
| 280 |
+
""")
|
| 281 |
+
|
| 282 |
+
gr.Markdown("### 🎯 Tips")
|
| 283 |
+
gr.Markdown("""
|
| 284 |
+
• Use web search for current events
|
| 285 |
+
• Lower temperature for factual answers
|
| 286 |
+
• Higher temperature for creative tasks
|
| 287 |
+
• Clear chat to reset context
|
| 288 |
+
""")
|
| 289 |
+
|
| 290 |
+
gr.Markdown("### 🔗 Links")
|
| 291 |
+
gr.Markdown("""
|
| 292 |
+
[Jan Official](https://jan.ai)
|
| 293 |
+
[Documentation](https://jan.ai/docs)
|
| 294 |
+
[GitHub](https://github.com/janhq/jan)
|
| 295 |
+
""")
|
| 296 |
|
| 297 |
+
# Funcionalidad
|
| 298 |
+
def respond(message, chat_history, temp, max_tok, web):
|
| 299 |
+
bot_message = jan_chat(message, chat_history, temp, max_tok, web)
|
| 300 |
+
chat_history.append([message, bot_message])
|
| 301 |
+
return "", chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
+
def clear_chat():
|
| 304 |
+
global chat_history
|
| 305 |
+
chat_history = []
|
| 306 |
+
return None
|
| 307 |
+
|
| 308 |
+
msg.submit(respond, [msg, chatbot, temperature_slider, max_tokens_slider, web_search_checkbox], [msg, chatbot])
|
| 309 |
+
send_btn.click(respond, [msg, chatbot, temperature_slider, max_tokens_slider, web_search_checkbox], [msg, chatbot])
|
| 310 |
+
clear_btn.click(clear_chat, None, chatbot)
|
| 311 |
|
| 312 |
gr.Markdown("""
|
| 313 |
+
---
|
| 314 |
+
<div style="text-align: center; color: #666; padding: 10px;">
|
| 315 |
+
Jan App Complete • Powered by Jan v1 (4B) • Running on HuggingFace Spaces
|
| 316 |
+
</div>
|
|
|
|
|
|
|
| 317 |
""")
|
| 318 |
|
| 319 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -1,4 +1,10 @@
|
|
| 1 |
-
#
|
|
|
|
|
|
|
| 2 |
gradio>=4.19.0
|
|
|
|
|
|
|
|
|
|
| 3 |
beautifulsoup4>=4.12.0
|
| 4 |
-
requests>=2.31.0
|
|
|
|
|
|
| 1 |
+
# Jan App Complete Requirements
|
| 2 |
+
transformers>=4.45.0
|
| 3 |
+
torch>=2.0.0
|
| 4 |
gradio>=4.19.0
|
| 5 |
+
accelerate>=0.25.0
|
| 6 |
+
bitsandbytes>=0.42.0
|
| 7 |
+
sentencepiece>=0.1.99
|
| 8 |
beautifulsoup4>=4.12.0
|
| 9 |
+
requests>=2.31.0
|
| 10 |
+
tokenizers>=0.15.0
|