aadidevopspro/Group_42_Assignment_Conversational_AI
This Space wires your original notebook code into a production-friendly Gradio app.
- Upload or commit your
data/qa.jsonl(165 Q/A) and use semantic search or your notebook's own RAG/FT functions. - We attempt to call your functions if their names match any of these:
- RAG:
answer_with_rag,rag_answer,get_rag_answer,answer_rag,answer_with_retrieval,predict_rag - FT:
ft_predict,generate_ft_answer,ft_answer,predict_ft,answer_with_ft
This bundle turns your notebook into a public Hugging Face Space that serves your fine‑tuned model (either full fine‑tuning or LoRA adapters).
Repo structure (what you got in this ZIP)
.
├─ app.py # Gradio UI (loads hub repo or ./model folder)
├─ requirements.txt # Space dependencies
├─ push_to_hub.py # Helper to upload your local model dir to a model repo
├─ train_from_notebook_notes.md # Mapping from your notebook sections to scripts
└─ model/ # (optional) place your exported weights here if not pushing to hubTip: Either push your model to the Hub and setMODEL_REPO, or drop the weights into./model/directory before deploying the Space.
Option A — Push your model to the Hub, then create the Space
- Export from your notebook run In your Colab/Notebook, after training finishes, you likely saved weights as either:
- Full FT (Section 3.4):
ft_flan_t5_small_full/ - LoRA adapters (Section 3.5):
ft_flan_t5_small_lora/(+run_config.json)
Download the chosen directory to your local machine.
- Create a _model_ repo on Hugging Face (e.g.
yourname/ft-flan-t5-small)
- Upload your weights using the helper script:
pip install -U huggingface_hub
export HF_TOKEN=hf_... # Settings → Access Tokens → New token (Write)
python push_to_hub.py \
--model_dir /path/to/ft_flan_t5_small_full \
--repo_id yourname/ft-flan-t5-small For LoRA, pass your adapter directory instead. The script uploads any files it finds (including run_config.json, which tells the Space the base model).
- Create a _Space_ (Gradio) on Hugging Face and upload these files from this ZIP:
app.pyrequirements.txtREADME.md(optional)
- In the Space Settings → Variables and secrets, set:
MODEL_REPO = yourname/ft-flan-t5-small- (optional)
BASE_MODEL = google/flan-t5-small(if your LoRA run used a different base)
- Deploy. Your Space will boot, download the model, and be public.
Option B — Bundle the model inside the Space
If you prefer not to use a separate model repo:
- Put your trained directory (e.g.
ft_flan_t5_small_full/orft_flan_t5_small_lora/) inside this folder and rename it tomodel/. - Zip & upload the whole Space directory as the initial commit when creating the Space.
- The Space will load
./model/automatically.
Note: Model files can be large; hub‑based loading is usually better.
LoRA vs Full FT — how the Space detects it
- If the model directory (local or hub) contains
adapter_model.safetensorsandadapter_config.json, the app assumes LoRA and will readrun_config.json’s"base_model"field to load the correct base (e.g.,"google/flan-t5-small") and then apply adapters. - Otherwise, it treats the directory as a full fine‑tuned model and loads directly.
Make sure you include a `run_config.json` alongside your saved weights; both your notebook sections 3.4 and 3.5 already save it.
Requirements & Hardware
- Default
requirements.txtcoverstransformers,torch,accelerate,peft,gradio,sentencepiece,safetensors,huggingface_hub. - Space hardware: CPU works but is slower. For better latency, choose a GPU Space type.
Optional: Enable your Gemini RAG
Your notebook also experimented with Gemini for RAG. If you want to expose that in your Space:
- Add
google-generativeaitorequirements.txt. - In Space Settings → Secrets, add
GEMINI_API_KEY. - Extend
app.pyto add a RAG mode that uses your chunk index + Gemini. (This skeleton focuses on the FT path only.)
Troubleshooting
- Space stuck on “Building”: dependencies compiling. Try pinning versions or using CPU.
- CUDA errors on CPU space: ensure
torchinstalls CPU build (Spaces usually handle this). - Wrong base for LoRA: ensure
run_config.jsonhas"base_model": "google/flan-t5-small". - Large downloads time out: prefer hosting the model in a Hub repo and letting Spaces cache it.
Minimal request format (how the prompt is built)
We format inputs as:
Question: <your question>
Answer:This matches typical T5 Q&A formatting for clean outputs.
Enjoy! 🎉
