Mhammad-Raller commited on
Commit
80174d0
·
verified ·
1 Parent(s): fdf7b2d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Raller Magnium AI - Powered by raller.pro
2
+ # Copyright (C) 2026
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License v3.
5
+
6
+ import gradio as gr
7
+ from transformers import pipeline
8
+
9
+ # Load the SmolLM 1.7B Instruct model
10
+ generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM-1.7B-Instruct")
11
+
12
+ def chat_respond(message, history):
13
+ # Format the conversation history for the model
14
+ prompt = ""
15
+ for user_msg, ai_msg in history:
16
+ prompt += f"User: {user_msg}\nAssistant: {ai_msg}\n"
17
+ prompt += f"User: {message}\nAssistant:"
18
+
19
+ # Generate response
20
+ results = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
21
+
22
+ # Extract only the newly generated text
23
+ full_text = results['generated_text']
24
+ response = full_text.split("Assistant:")[-1].strip()
25
+ return response
26
+
27
+ # Build a clean chatbot UI matching raller.pro
28
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
29
+ gr.Markdown("# 🤖 Raller Magnium AI")
30
+ gr.Markdown("Welcome to the official open-source AI engine for raller.pro.")
31
+
32
+ gr.ChatInterface(
33
+ fn=chat_respond,
34
+ textbox=gr.Textbox(placeholder="Ask Raller Magnium anything...", container=False, scale=7),
35
+ retry_btn="🔄 Retry",
36
+ undo_btn="↩️ Undo",
37
+ clear_btn="🗑️ Clear Chat",
38
+ )
39
+
40
+ demo.launch()