burhan112 commited on
Commit
1c701d2
Β·
verified Β·
1 Parent(s): bdd8faa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+ import random
5
+
6
+ # Model path and loading
7
+ MODEL_PATH = "emojiFinetune"
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
9
+ model = AutoModelForCausalLM.from_pretrained(MODEL_PATH).to("cuda" if torch.cuda.is_available() else "cpu")
10
+
11
+ # Emoji brainpower function
12
+ def emojiq_brainpower():
13
+ logic = random.randint(40, 100)
14
+ emoji_confusion = 100 - logic
15
+ caffeine = random.randint(10, 50)
16
+ return (
17
+ f"🧠 {logic}% logic, {emoji_confusion}% 'Wait... is πŸ• a number?!' πŸ€”, "
18
+ f"and {caffeine}% caffeine boost β˜•πŸš€"
19
+ )
20
+
21
+ # Function to solve emoji math problem
22
+ def solve_emoji_math(problem, temperature, max_length, top_p):
23
+ if not problem.strip():
24
+ return "⚠️ Please enter an emoji math problem to solve.", ""
25
+
26
+ prompt = f"Solve: {problem}\nAnswer:"
27
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
28
+
29
+ with torch.no_grad():
30
+ outputs = model.generate(
31
+ **inputs,
32
+ max_length=max_length,
33
+ temperature=temperature,
34
+ top_p=top_p,
35
+ do_sample=True
36
+ )
37
+
38
+ solution = tokenizer.decode(outputs[0], skip_special_tokens=True)
39
+ solved_text = solution.split("Answer:")[-1].strip()
40
+ brainpower = emojiq_brainpower()
41
+
42
+ return f"βœ… Solution: **{solved_text}**", brainpower
43
+
44
+ # Gradio interface
45
+ with gr.Blocks(title="EmojIQ - Emoji Math Solver") as interface:
46
+ gr.Markdown("# πŸ”’ EmojIQ: Emoji Math Solver")
47
+ gr.Markdown("### Cracking Emoji Codes, Solving Math with a Smile! πŸ˜ƒβž•πŸŽ­")
48
+ gr.Markdown("Enter an emoji math problem, and let EmojIQ solve it! πŸ€“")
49
+
50
+ # Input section
51
+ problem_input = gr.Textbox(
52
+ label="πŸ“ Emoji Math Problem",
53
+ placeholder="e.g., 🍎 + 🍎 + 🍎 = 12",
54
+ lines=3
55
+ )
56
+
57
+ # Model settings in a column
58
+ with gr.Row():
59
+ with gr.Column():
60
+ temperature = gr.Slider(0.0, 1.5, value=0.7, step=0.1, label="Temperature (0 = logical, 1 = creative)")
61
+ max_length = gr.Slider(50, 200, value=100, step=10, label="Max Output Length")
62
+ top_p = gr.Slider(0.0, 1.0, value=0.9, step=0.05, label="Top-p (sampling diversity)")
63
+
64
+ # Output section
65
+ solution_output = gr.Textbox(label="Solution", interactive=False)
66
+ brainpower_output = gr.Textbox(label="EmojIQ Brainpower", interactive=False)
67
+
68
+ # Solve button
69
+ solve_button = gr.Button("πŸ” Solve Emoji Math")
70
+ solve_button.click(
71
+ fn=solve_emoji_math,
72
+ inputs=[problem_input, temperature, max_length, top_p],
73
+ outputs=[solution_output, brainpower_output]
74
+ )
75
+
76
+ gr.Markdown("---")
77
+ gr.Markdown("πŸ”’ **EmojIQ** - Cracking Emoji Codes, One Equation at a Time! πŸš€")
78
+
79
+ # Launch the interface
80
+ interface.launch(share=True)