prakhardoneria commited on
Commit
d8f48c5
·
verified ·
1 Parent(s): 380cd48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -27
app.py CHANGED
@@ -1,39 +1,20 @@
1
- import os
2
  import gradio as gr
3
- from huggingface_hub import hf_hub_download
4
- from llama_cpp import Llama
5
 
6
- # Model config
7
- MODEL_REPO = "TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF"
8
- MODEL_FILE = "TinyLlama-1.1B-Chat-v1.0.Q4_K_M.gguf"
9
 
10
- # Download and cache model
11
- try:
12
- model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, cache_dir="./models")
13
- except Exception as e:
14
- raise RuntimeError(f"Failed to download model: {e}") from e
15
-
16
- # Load with llama-cpp
17
- llm = Llama(
18
- model_path=model_path,
19
- n_ctx=2048,
20
- n_threads=4,
21
- use_mlock=True
22
- )
23
-
24
- # Answer function
25
  def answer_question(question):
26
- prompt = f"[INST] {question} [/INST]"
27
- output = llm(prompt, max_tokens=256, temperature=0.7, top_p=0.9, stop=["</s>"])
28
- return output["choices"][0]["text"].strip()
29
 
30
- # Gradio app
31
  demo = gr.Interface(
32
  fn=answer_question,
33
  inputs=gr.Textbox(lines=2, label="Ask a programming question"),
34
  outputs=gr.Textbox(label="Answer"),
35
- title="TinyLlama Code Assistant",
36
- description="Lightweight Q&A with TinyLlama (1.1B GGUF)."
37
  )
38
 
39
  if __name__ == "__main__":
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
 
4
+ # Load lightweight Flan-T5 model
5
+ qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-base")
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def answer_question(question):
8
+ prompt = f"Answer the following programming question clearly:\n{question}"
9
+ result = qa_pipeline(prompt, max_length=200, do_sample=True, top_p=0.9, temperature=0.7)[0]["generated_text"]
10
+ return result.strip()
11
 
 
12
  demo = gr.Interface(
13
  fn=answer_question,
14
  inputs=gr.Textbox(lines=2, label="Ask a programming question"),
15
  outputs=gr.Textbox(label="Answer"),
16
+ title="Lightweight Code Q&A (Flan-T5)",
17
+ description="Ask coding questions and get short, helpful answers using the Flan-T5 model."
18
  )
19
 
20
  if __name__ == "__main__":