Spaces:
Sleeping

File size: 1,584 Bytes
9e84f1f
b150ab1
 
 
 
21bf0a5
ba4a5a5
b150ab1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18f9d32
b150ab1
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import spaces
import gradio as gr
from transformers import pipeline

# Downloads & runs YOUR model directly on Hugging Face's big cloud server (0 MB on your PC!)
ai_brain = pipeline("text-generation",  model="Qwen/Qwen2.5-0.5B-Instruct")
@spaces.GPU
def superbot_reply(message, history, uploaded_file):
    extra_context = ""
    
    # Reads uploaded file in temporary RAM and discards it immediately so the server never overflows!
    if uploaded_file is not None:
        with open(uploaded_file.name, "r", encoding="utf-8", errors="ignore") as f:
            extra_context = f"\n\n[User File Content]:\n{f.read()[:4000]}"

    messages = [
        {"role": "system", "content": "You are SuperBot, an advanced AI created by the Founder. Think step-by-step and give clear, helpful answers."}
    ]
    
    # Add recent conversation memory
    for user_msg, bot_msg in history[-5:]:
        messages.append({"role": "user", "content": user_msg})
        messages.append({"role": "assistant", "content": bot_msg})

    messages.append({"role": "user", "content": message + extra_context})
    
    result = ai_brain(messages, max_new_tokens=150)
    return result[0]["generated_text"][-1]["content"]

demo = gr.ChatInterface(
    fn=superbot_reply,
    additional_inputs=[
        gr.File(label="Optional File Upload (Auto-wiped after reply so server never overflows)")
    ],
    title="🤖 SuperBot AI — Cloud Server Edition",
    description="Built by the Founder. Runs 100% on cloud servers with zero local PC storage!"
)

demo.launch()