arinbalyan commited on
Commit
16dff3b
·
verified ·
1 Parent(s): a1b6bb3

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +10 -6
  2. app.py +65 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,17 @@
1
  ---
2
- title: Science Chat
3
- emoji: 💻
4
- colorFrom: yellow
5
- colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 6.19.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
1
  ---
2
+ title: Science Tutor
3
+ emoji: 🔬
4
+ colorFrom: green
5
+ colorTo: gray
6
  sdk: gradio
7
  sdk_version: 6.19.0
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # Science Tutor
13
+
14
+ **Model:** arinbalyan/deepseek-science
15
+
16
+ ## Links
17
+ - **HF Profile:** [arinbalyan](https://huggingface.co/arinbalyan)
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ MODEL_ID = "arinbalyan/deepseek-science"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
8
+ if tokenizer.pad_token is None:
9
+ tokenizer.pad_token = tokenizer.eos_token
10
+
11
+ model = AutoModelForCausalLM.from_pretrained(
12
+ MODEL_ID,
13
+ torch_dtype=torch.float16,
14
+ device_map="auto",
15
+ )
16
+
17
+ def generate(prompt, history):
18
+ if not prompt.strip():
19
+ return "", history
20
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
21
+ with torch.no_grad():
22
+ out = model.generate(
23
+ **inputs,
24
+ max_new_tokens=200,
25
+ temperature=0.8,
26
+ do_sample=True,
27
+ pad_token_id=tokenizer.eos_token_id,
28
+ )
29
+ response = tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
30
+ history.append((prompt, response.strip()))
31
+ return "", history
32
+
33
+ theme = (
34
+ gr.themes.Soft(primary_hue="teal", neutral_hue="slate")
35
+ .set(
36
+ button_primary_background_fill_hover="#0d9488",
37
+ button_primary_text_color="white",
38
+ input_background_fill="#f8fafc",
39
+ input_border_color="#e2e8f0",
40
+ input_border_color_focus="#0d9488",
41
+ )
42
+ )
43
+
44
+ css = """.gradio-container { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important; }
45
+ .main-header { text-align: center; padding: 2rem 1rem; background: linear-gradient(135deg, #0d9488 0%, #0d9488dd 100%); color: white; border-radius: 12px; margin-bottom: 1rem; }
46
+ .main-header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.25rem; }
47
+ .main-header p { font-size: 1rem; opacity: 0.9; }
48
+ .footer { text-align: center; padding: 1rem; color: #64748b; font-size: 0.875rem; }"""
49
+
50
+ with gr.Blocks(title="Science Tutor") as demo:
51
+ with gr.Row():
52
+ with gr.Column():
53
+ gr.HTML(f"""<div class="main-header"><h1>🔬 Science Tutor</h1><p>Generate with AI</p></div>""")
54
+ chatbot = gr.Chatbot(height=400)
55
+ msg = gr.Textbox(label="Prompt", placeholder='e.g., What is photosynthesis?', lines=2)
56
+ with gr.Row():
57
+ submit = gr.Button("Generate", variant="primary", size="lg", scale=1)
58
+ clear = gr.Button("Clear", size="lg", scale=0)
59
+ gr.Examples(examples=["What is photosynthesis?", "Explain Newton's laws of motion", "How does DNA replication work?", "What causes the seasons on Earth?", "Explain the periodic table trends"], inputs=msg, label="Try these")
60
+ gr.HTML(f"""<div class="footer">DeepSeek-R1-Distill-Qwen-1.5B on science data</div>""")
61
+ submit.click(generate, [msg, chatbot], [msg, chatbot])
62
+ clear.click(lambda: None, None, chatbot, queue=False)
63
+
64
+ if __name__ == "__main__":
65
+ demo.launch(theme=theme, css=css)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers>=4.40
2
+ torch>=2.0
3
+ accelerate>=1.0