Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
|
|
|
|
40 |
'''
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
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 |
|