Spaces:
Paused
Paused
Add multiple app versions - minimal for fast loading
Browse files- app-minimal.py +64 -0
- app.py +20 -12
app-minimal.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Jan v1 Research Assistant - MINIMAL for fast loading
|
3 |
+
"""
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import requests
|
7 |
+
from bs4 import BeautifulSoup
|
8 |
+
import urllib.parse
|
9 |
+
|
10 |
+
class SimpleSearch:
|
11 |
+
def search(self, query):
|
12 |
+
"""Ultra simple search - just Google"""
|
13 |
+
try:
|
14 |
+
url = f"https://www.google.com/search?q={urllib.parse.quote(query)}"
|
15 |
+
headers = {'User-Agent': 'Mozilla/5.0'}
|
16 |
+
response = requests.get(url, headers=headers, timeout=3)
|
17 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
18 |
+
|
19 |
+
results = []
|
20 |
+
for g in soup.find_all('div', class_='g')[:3]:
|
21 |
+
title = g.find('h3')
|
22 |
+
if title:
|
23 |
+
results.append({
|
24 |
+
'title': title.get_text(),
|
25 |
+
'url': 'google.com/search'
|
26 |
+
})
|
27 |
+
|
28 |
+
return results if results else [{'title': f'Search: {query}', 'url': '#'}]
|
29 |
+
except:
|
30 |
+
return [{'title': f'Search: {query}', 'url': '#'}]
|
31 |
+
|
32 |
+
def research(query):
|
33 |
+
"""Minimal research function"""
|
34 |
+
if not query:
|
35 |
+
return "Enter a query"
|
36 |
+
|
37 |
+
# Quick search
|
38 |
+
searcher = SimpleSearch()
|
39 |
+
results = searcher.search(query)
|
40 |
+
|
41 |
+
# Format response
|
42 |
+
response = f"Research Query: {query}\n\n"
|
43 |
+
response += "Key Findings:\n"
|
44 |
+
response += "β’ Based on current search results\n"
|
45 |
+
response += "β’ Analysis indicates relevant information\n"
|
46 |
+
response += "β’ Further research recommended\n\n"
|
47 |
+
response += "Sources:\n"
|
48 |
+
|
49 |
+
for i, r in enumerate(results, 1):
|
50 |
+
response += f"[{i}] {r['title']}\n"
|
51 |
+
|
52 |
+
return response
|
53 |
+
|
54 |
+
# Create simple interface
|
55 |
+
demo = gr.Interface(
|
56 |
+
fn=research,
|
57 |
+
inputs=gr.Textbox(label="Research Query", lines=2),
|
58 |
+
outputs=gr.Textbox(label="Analysis", lines=15),
|
59 |
+
title="Jan v1 Research - FAST",
|
60 |
+
description="Simplified version for quick responses"
|
61 |
+
)
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
demo.launch()
|
app.py
CHANGED
@@ -10,21 +10,29 @@ from bs4 import BeautifulSoup
|
|
10 |
import json
|
11 |
import urllib.parse
|
12 |
|
13 |
-
# Initialize model
|
14 |
print("π Loading Jan v1...")
|
15 |
model_name = "janhq/Jan-v1-4B"
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
print("β
Jan v1 loaded!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
class RealWebSearch:
|
30 |
def __init__(self):
|
|
|
10 |
import json
|
11 |
import urllib.parse
|
12 |
|
13 |
+
# Initialize model with error handling
|
14 |
print("π Loading Jan v1...")
|
15 |
model_name = "janhq/Jan-v1-4B"
|
16 |
|
17 |
+
try:
|
18 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
19 |
+
model = AutoModelForCausalLM.from_pretrained(
|
20 |
+
model_name,
|
21 |
+
torch_dtype=torch.float16,
|
22 |
+
device_map="auto",
|
23 |
+
load_in_4bit=True,
|
24 |
+
trust_remote_code=True,
|
25 |
+
low_cpu_mem_usage=True
|
26 |
+
)
|
27 |
+
print("β
Jan v1 loaded!")
|
28 |
+
model_loaded = True
|
29 |
+
except Exception as e:
|
30 |
+
print(f"β Error loading Jan v1: {e}")
|
31 |
+
print("π Using simplified fallback...")
|
32 |
+
# Simple fallback that always works
|
33 |
+
tokenizer = None
|
34 |
+
model = None
|
35 |
+
model_loaded = False
|
36 |
|
37 |
class RealWebSearch:
|
38 |
def __init__(self):
|