File size: 2,719 Bytes
1c701d2
 
 
 
 
96f001c
2acc877
1c701d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96f001c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import random

# Model path (relative to the Space root)
MODEL_PATH = "./emoji_deepseekmath-r1"
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH).to("cuda" if torch.cuda.is_available() else "cpu")

def emojiq_brainpower():  
    logic = random.randint(40, 100)  
    emoji_confusion = 100 - logic  
    caffeine = random.randint(10, 50)  
    return (  
        f"🧠 {logic}% logic, {emoji_confusion}% 'Wait... is πŸ• a number?!' πŸ€”, "  
        f"and {caffeine}% caffeine boost β˜•πŸš€"  
    )  

def solve_emoji_math(problem, temperature, max_length, top_p):
    if not problem.strip():
        return "⚠️ Please enter an emoji math problem to solve.", ""
    
    prompt = f"Solve: {problem}\nAnswer:"
    inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
    
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_length=max_length,
            temperature=temperature,
            top_p=top_p,
            do_sample=True
        )
    
    solution = tokenizer.decode(outputs[0], skip_special_tokens=True)
    solved_text = solution.split("Answer:")[-1].strip()
    brainpower = emojiq_brainpower()
    
    return f"βœ… Solution: **{solved_text}**", brainpower

with gr.Blocks(title="EmojIQ - Emoji Math Solver") as interface:
    gr.Markdown("# πŸ”’ EmojIQ: Emoji Math Solver")
    gr.Markdown("### Cracking Emoji Codes, Solving Math with a Smile! πŸ˜ƒβž•πŸŽ­")
    gr.Markdown("Enter an emoji math problem, and let EmojIQ solve it! πŸ€“")

    problem_input = gr.Textbox(
        label="πŸ“ Emoji Math Problem",
        placeholder="e.g., 🍎 + 🍎 + 🍎 = 12",
        lines=3
    )

    with gr.Row():
        with gr.Column():
            temperature = gr.Slider(0.0, 1.5, value=0.7, step=0.1, label="Temperature (0 = logical, 1 = creative)")
            max_length = gr.Slider(50, 200, value=100, step=10, label="Max Output Length")
            top_p = gr.Slider(0.0, 1.0, value=0.9, step=0.05, label="Top-p (sampling diversity)")

    solution_output = gr.Textbox(label="Solution", interactive=False)
    brainpower_output = gr.Textbox(label="EmojIQ Brainpower", interactive=False)

    solve_button = gr.Button("πŸ” Solve Emoji Math")
    solve_button.click(
        fn=solve_emoji_math,
        inputs=[problem_input, temperature, max_length, top_p],
        outputs=[solution_output, brainpower_output]
    )

    gr.Markdown("---")
    gr.Markdown("πŸ”’ **EmojIQ** - Cracking Emoji Codes, One Equation at a Time! πŸš€")

interface.launch()