kat33 commited on
Commit
f20f7fd
1 Parent(s): 8e7b3df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os # to check if file exists
2
  import sys # to flush stdout
 
3
 
4
  import gradio as gr
5
  #import transformers
@@ -35,33 +36,39 @@ def question_answer(context, question, max_tokens):
35
  llm = Llama(model_path=mfile)
36
  output = llm(text, max_tokens=max_tokens, stop=["### Response"], echo=True)
37
  print(output)
 
 
 
 
38
 
39
- return question, gr.Markdown(output['choices'][0]['text'])
 
 
40
  '''
41
- Output is of the form:
42
- {
43
- "id": "cmpl-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
44
- "object": "text_completion",
45
- "created": 1679561337,
46
- "model": "./models/7B/ggml-model.bin",
47
- "choices": [
48
- {
49
- "text": "Q: Name the planets in the solar system? A: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune and Pluto.",
50
- "index": 0,
51
- "logprobs": None,
52
- "finish_reason": "stop"
53
- }
54
- ],
55
- "usage": {
56
- "prompt_tokens": 14,
57
- "completion_tokens": 28,
58
- "total_tokens": 42
59
- }
60
- }
61
  '''
62
 
 
63
  #generator = pipeline(model=model, device_map="auto")
64
-
65
  #return generator(text)
66
 
67
 
 
1
  import os # to check if file exists
2
  import sys # to flush stdout
3
+ import markdown # to render answer
4
 
5
  import gradio as gr
6
  #import transformers
 
36
  llm = Llama(model_path=mfile)
37
  output = llm(text, max_tokens=max_tokens, stop=["### Response"], echo=True)
38
  print(output)
39
+
40
+ # remove the context and leave only the answer
41
+ answer=output['choices'][0]['text']
42
+ answer = answer.replace(text, "", 1)
43
 
44
+ # render the markdown and return the html and question
45
+ html_answer = markdown.markdown(answer)
46
+ return question, html_answer
47
  '''
48
+ Output is of the form:
49
+ {
50
+ "id": "cmpl-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
51
+ "object": "text_completion",
52
+ "created": 1679561337,
53
+ "model": "./models/7B/ggml-model.bin",
54
+ "choices": [
55
+ {
56
+ "text": "Q: Name the planets in the solar system? A: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune and Pluto.",
57
+ "index": 0,
58
+ "logprobs": None,
59
+ "finish_reason": "stop"
60
+ }
61
+ ],
62
+ "usage": {
63
+ "prompt_tokens": 14,
64
+ "completion_tokens": 28,
65
+ "total_tokens": 42
66
+ }
67
+ }
68
  '''
69
 
70
+ # old transformers code
71
  #generator = pipeline(model=model, device_map="auto")
 
72
  #return generator(text)
73
 
74