Group2255 commited on
Commit
a7c78de
ยท
verified ยท
1 Parent(s): be68b44

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +18 -0
  2. README.md +91 -6
  3. app.py +60 -0
  4. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ # Set working directory
4
+ WORKDIR /app
5
+
6
+ # Copy files
7
+ COPY requirements.txt requirements.txt
8
+ COPY app.py app.py
9
+ COPY README.md README.md
10
+
11
+ # Install dependencies
12
+ RUN pip install --no-cache-dir -r requirements.txt
13
+
14
+ # Expose default Streamlit port
15
+ EXPOSE 8501
16
+
17
+ # Command to run the app
18
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.enableCORS=false"]
README.md CHANGED
@@ -1,12 +1,97 @@
1
  ---
2
  title: Programming Help Chatbot
3
- emoji: ๐Ÿข
4
- colorFrom: green
5
- colorTo: pink
6
- sdk: docker
 
 
7
  pinned: false
8
- license: mit
9
- short_description: programming chatbot
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Programming Help Chatbot
3
+ emoji: ๐Ÿ’ป
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: streamlit
7
+ sdk_version: "1.20.0"
8
+ app_file: app.py
9
  pinned: false
 
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
+
14
+ ---
15
+
16
+ # Programming Help Chatbot ๐Ÿค–
17
+
18
+ A Minimal Viable Product (MVP) AI chatbot built as part of the **AML-3304** assignment:
19
+ **"From Tokens to Transformers โ€“ Building AI Systems with Embeddings, Generative Models, and MLOps."**
20
+
21
+ ---
22
+
23
+ ## ๐Ÿ” Project Overview
24
+
25
+ This chatbot is designed to assist with programming-related queries. It leverages a pretrained generative transformer model to provide real-time code suggestions in response to natural language inputs. This is not a rule-based system, but a lightweight generative AI application hosted on Hugging Face Spaces.
26
+
27
+ - **Model:** `Salesforce/codegen-350M-mono` (Pretrained by Salesforce Research)
28
+ - **Frontend:** Streamlit
29
+ - **Framework:** Hugging Face Transformers + PyTorch
30
+ - **Hosting:** Hugging Face Spaces (Free CPU Tier)
31
+ - **Deployment:** Manual Git-based CI/CD with automated runtime build
32
+
33
+ ---
34
+
35
+ ## โœจ Features
36
+
37
+ - Accepts open-ended natural language programming questions
38
+ - Generates accurate code snippets (Python, JavaScript, etc.)
39
+ - Intuitive UI powered by Streamlit
40
+ - Minimal resource usage (compatible with Hugging Face Free Tier)
41
+
42
+ ---
43
+
44
+ ## ๐Ÿง  AI Design Elements
45
+
46
+ | Element | Integration |
47
+ |---------------------|-----------------------------------------------------|
48
+ | Embeddings | Handled internally via pretrained model tokenizer |
49
+ | Bayesian-style sampling | `do_sample=True` with temperature in generation |
50
+ | Generative Language Model | `Salesforce/codegen-350M-mono` (Causal LM) |
51
+ | PyTorch Backend | Used via `AutoModelForCausalLM` |
52
+
53
+ ---
54
+
55
+ ## ๐Ÿ› ๏ธ Technologies Used
56
+
57
+ - Python 3.9+
58
+ - Streamlit
59
+ - Hugging Face Transformers
60
+ - PyTorch
61
+ - Hugging Face Spaces
62
+
63
+ ---
64
+
65
+ ## ๐Ÿš€ Usage Instructions
66
+
67
+ 1. Visit the live space:
68
+ ๐Ÿ‘‰ `https://huggingface.co/spaces/YOUR_USERNAME/programming-help-chatbot`
69
+
70
+ 2. Type your question into the input box, e.g.:
71
+ ```
72
+ Write a Python function to check if a number is a prime.
73
+ ```
74
+
75
+ 3. Press โ€œGenerate Codeโ€ and view the results in a highlighted code block.
76
+
77
+ ---
78
+
79
+ ## ๐Ÿ“ฆ Installation (For Local Testing)
80
+
81
+ ```bash
82
+ pip install streamlit transformers torch
83
+ streamlit run app.py
84
+ ```
85
+
86
+ ---
87
+
88
+ ## ๐Ÿ“œ License
89
+
90
+ This project is licensed under the MIT License.
91
+
92
+ ---
93
+
94
+ ## ๐Ÿ‘ค Author
95
+
96
+ Created by **[Your Name]**
97
+ Part of the AML-3304 Course Project Submission
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ # Programming Help Chatbot โ€“ AI Chatbot MVP (AML-3304)
3
+ # Built using Streamlit and Hugging Face Transformers
4
+ # Model: Salesforce/codegen-350M-mono
5
+
6
+ import streamlit as st
7
+ from transformers import AutoTokenizer, AutoModelForCausalLM
8
+ import torch
9
+
10
+ # Set Streamlit page configuration
11
+ st.set_page_config(page_title="Programming Help Chatbot", layout="centered")
12
+
13
+ # Page Title and Description
14
+ st.title("๐Ÿ‘จโ€๐Ÿ’ป Programming Help Chatbot")
15
+ st.markdown("""
16
+ Welcome to the AI-powered programming assistant!
17
+ This chatbot uses a pretrained transformer model to generate helpful code snippets for Python, JavaScript, and more.
18
+ """)
19
+
20
+ # Load pretrained code generation model and tokenizer
21
+ @st.cache_resource
22
+ def load_codegen_model():
23
+ """
24
+ Load the Salesforce/codegen-350M-mono model and tokenizer.
25
+ Cached to avoid reloading on every interaction.
26
+ """
27
+ model_name = "Salesforce/codegen-350M-mono"
28
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
29
+ model = AutoModelForCausalLM.from_pretrained(model_name)
30
+ return tokenizer, model
31
+
32
+ # Initialize model and tokenizer
33
+ tokenizer, model = load_codegen_model()
34
+
35
+ # User input prompt
36
+ user_query = st.text_area(
37
+ label="๐Ÿ“ Enter your programming question:",
38
+ height=150,
39
+ placeholder="Example: Write a Python function to check for palindrome strings"
40
+ )
41
+
42
+ # Generate code on button click
43
+ if st.button("Generate Code"):
44
+ if user_query.strip():
45
+ # Encode input and generate code
46
+ inputs = tokenizer(user_query, return_tensors="pt")
47
+ outputs = model.generate(
48
+ inputs["input_ids"],
49
+ max_length=256,
50
+ do_sample=True,
51
+ temperature=0.7,
52
+ pad_token_id=tokenizer.eos_token_id
53
+ )
54
+ generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
55
+
56
+ # Display result
57
+ st.subheader("๐Ÿ’ก Suggested Code:")
58
+ st.code(generated_code, language="python")
59
+ else:
60
+ st.warning("Please enter a valid programming question.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit>=1.20.0
2
+ transformers>=4.36.0
3
+ torch>=2.0.0