CoolFace
Apppublic

aadidevopspro/Group_42_Assignment_Conversational_AI

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
App README

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 hub
Tip: Either push your model to the Hub and set MODEL_REPO, or drop the weights into ./model/ directory before deploying the Space.

Option A — Push your model to the Hub, then create the Space

  1. 1.Export from your notebook run In your Colab/Notebook, after training finishes, you likely saved weights as either:
  2. 2.Full FT (Section 3.4): ft_flan_t5_small_full/
  3. 3.LoRA adapters (Section 3.5): ft_flan_t5_small_lora/ (+ run_config.json)

Download the chosen directory to your local machine.

  1. 1.Create a _model_ repo on Hugging Face (e.g. yourname/ft-flan-t5-small)
  1. 1.Upload your weights using the helper script:
bash
   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).

  1. 1.Create a _Space_ (Gradio) on Hugging Face and upload these files from this ZIP:
  2. 2.app.py
  3. 3.requirements.txt
  4. 4.README.md (optional)
  1. 1.In the Space Settings → Variables and secrets, set:
  2. 2.MODEL_REPO = yourname/ft-flan-t5-small
  3. 3.(optional) BASE_MODEL = google/flan-t5-small (if your LoRA run used a different base)
  1. 1.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:

  1. 1.Put your trained directory (e.g. ft_flan_t5_small_full/ or ft_flan_t5_small_lora/) inside this folder and rename it to model/.
  2. 2.Zip & upload the whole Space directory as the initial commit when creating the Space.
  3. 3.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.safetensors and adapter_config.json, the app assumes LoRA and will read run_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.txt covers transformers, 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:

  1. 1.Add google-generativeai to requirements.txt.
  2. 2.In Space Settings → Secrets, add GEMINI_API_KEY.
  3. 3.Extend app.py to 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 torch installs CPU build (Spaces usually handle this).
  • —Wrong base for LoRA: ensure run_config.json has "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! 🎉