kat33 commited on
Commit
cd5e755
1 Parent(s): 5ce765e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -4
app.py CHANGED
@@ -1,13 +1,43 @@
1
  import gradio as gr
2
- import transformers
3
- from transformers import pipeline
 
4
 
5
  model="TheBloke/Nous-Hermes-13B-GGML"
 
6
 
7
  def question_answer(context, question):
8
- generator = pipeline(model=model, device_map="auto")
9
  text=context + "\n\nQuestion: \"\"\"\n" + question + "\nPlease use markdown formatting for answer. \nAnswer:\n"
10
- return generator(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  app=gr.Interface(fn=question_answer, inputs=["text", "text"], outputs=["textbox", "text"])
 
1
  import gradio as gr
2
+ #import transformers
3
+ #from transformers import pipeline
4
+ from llama_cpp import Llama
5
 
6
  model="TheBloke/Nous-Hermes-13B-GGML"
7
+ model="https://huggingface.co/TheBloke/Nous-Hermes-13B-GGML/resolve/main/nous-hermes-13b.ggmlv3.q4_K_S.bin"
8
 
9
  def question_answer(context, question):
 
10
  text=context + "\n\nQuestion: \"\"\"\n" + question + "\nPlease use markdown formatting for answer. \nAnswer:\n"
11
+ llm = Llama(model_path=model)
12
+ output = llm(text, max_tokens=33, stop=["### Response", "\n"], echo=True)
13
+ print(output)
14
+ return output.choices[0].text
15
+ '''
16
+ Output is of the form:
17
+ {
18
+ "id": "cmpl-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
19
+ "object": "text_completion",
20
+ "created": 1679561337,
21
+ "model": "./models/7B/ggml-model.bin",
22
+ "choices": [
23
+ {
24
+ "text": "Q: Name the planets in the solar system? A: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune and Pluto.",
25
+ "index": 0,
26
+ "logprobs": None,
27
+ "finish_reason": "stop"
28
+ }
29
+ ],
30
+ "usage": {
31
+ "prompt_tokens": 14,
32
+ "completion_tokens": 28,
33
+ "total_tokens": 42
34
+ }
35
+ }
36
+ '''
37
+
38
+ #generator = pipeline(model=model, device_map="auto")
39
+
40
+ #return generator(text)
41
 
42
 
43
  app=gr.Interface(fn=question_answer, inputs=["text", "text"], outputs=["textbox", "text"])