Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,15 @@
|
|
1 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
Hassan: In Lagos for a week, then Paris or London.
|
12 |
-
person: How's it going?
|
13 |
-
Hassan: Not bad.. Just trying to hit EV (escape velocity) with my startup
|
14 |
-
person: """
|
15 |
|
16 |
-
|
17 |
-
res = [s]
|
18 |
-
for sep in seps:
|
19 |
-
s, res = res, []
|
20 |
-
for seq in s:
|
21 |
-
res += seq.split(sep)
|
22 |
-
return res
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
p = prompt + input
|
27 |
-
input_ids = tokenizer(p, return_tensors="pt").input_ids
|
28 |
-
gen_tokens = model.generate(input_ids, do_sample=True, temperature=0.7, max_length=150,)
|
29 |
-
gen_text = tokenizer.batch_decode(gen_tokens)[0]
|
30 |
-
# print(gen_text)
|
31 |
-
result = gen_text[len(p):]
|
32 |
-
# print(">", result)
|
33 |
-
result = my_split(result, [']', '\n'])[1]
|
34 |
-
# print(">>", result)
|
35 |
-
if "Hassan: " in result:
|
36 |
-
result = result.split("Hassan: ")[-1]
|
37 |
-
# print(">>>", result)
|
38 |
-
return result
|
39 |
-
|
40 |
-
import gradio as gr
|
41 |
-
|
42 |
-
def chat(message):
|
43 |
-
history = gr.get_state() or []
|
44 |
-
print(history)
|
45 |
-
response = chat_base(message)
|
46 |
-
history.append((message, response))
|
47 |
-
gr.set_state(history)
|
48 |
-
html = "<div class='chatbot'>"
|
49 |
-
for user_msg, resp_msg in history:
|
50 |
-
html += f"<div class='user_msg'>{user_msg}</div>"
|
51 |
-
html += f"<div class='resp_msg'>{resp_msg}</div>"
|
52 |
-
html += "</div>"
|
53 |
-
return response
|
54 |
-
|
55 |
-
iface = gr.Interface(chat_base, gr.inputs.Textbox(label="Ask Hassan a Question"), "text", allow_screenshot=False, allow_flagging=False)
|
56 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Hugging Face์์ ๋ชจ๋ธ ๋ก๋
|
5 |
+
qa_model = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad")
|
6 |
|
7 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
8 |
+
def question_answering(question):
|
9 |
+
answer = qa_model(question)["answer"]
|
10 |
+
return answer
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
iface = gr.Interface(fn=question_answering, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# Gradio ์ฑ ์คํ
|
15 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|