ehi20011 commited on
Commit
2208bb7
·
verified ·
1 Parent(s): 32cca2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -9
app.py CHANGED
@@ -1,13 +1,36 @@
 
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- qa = pipeline("text2text-generation", model="google/flan-t5-base")
 
5
 
6
- def answer_question(prompt):
7
- output = qa(prompt, max_length=256, do_sample=False)
8
- return output[0]['generated_text']
 
 
 
 
 
 
9
 
10
- gr.Interface(fn=answer_question,
11
- inputs=gr.Textbox(label="Ask EduBot"),
12
- outputs=gr.Textbox(label="Answer"),
13
- title="Leo9 EduBot (CPU)").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
  import gradio as gr
3
+ from llama_cpp import Llama
4
 
5
+ # Load GGUF model
6
+ MODEL_PATH = "./models/mistral.gguf"
7
 
8
+ llm = Llama(
9
+ model_path=MODEL_PATH,
10
+ n_ctx=2048,
11
+ n_threads=9, # Increase for more speed if CPU allows
12
+ n_batch=128,
13
+ use_mlock=True,
14
+ use_mmap=True,
15
+ verbose=False
16
+ )
17
 
18
+ # Streaming generator
19
+ def generate_response(prompt):
20
+ stream = llm(
21
+ prompt=f"[INST] {prompt.strip()} [/INST]",
22
+ max_tokens=512,
23
+ stop=["</s>"],
24
+ stream=True
25
+ )
26
+ partial = ""
27
+ for chunk in stream:
28
+ partial += chunk["choices"][0]["text"]
29
+ yield partial
30
+
31
+ # Gradio UI
32
+ gr.ChatInterface(
33
+ fn=generate_response,
34
+ title="Leo9 AI Tutor",
35
+ description="An ai chatbots who answer any question.",
36
+ ).launch()