Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ tokenizer = AutoTokenizer.from_pretrained("ping98k/typhoon-7b-rag-instruct-th")
|
|
7 |
model = AutoModelForCausalLM.from_pretrained("ping98k/typhoon-7b-rag-instruct-th", device_map={"": 0})
|
8 |
|
9 |
@spaces.GPU(duration=120)
|
10 |
-
def response(instruction, history, inputText):
|
11 |
inp = f"""### Instruction:
|
12 |
{instruction}
|
13 |
|
@@ -18,7 +18,7 @@ def response(instruction, history, inputText):
|
|
18 |
|
19 |
### Response:"""
|
20 |
print(f"Ask: {instruction}")
|
21 |
-
|
22 |
input_ids = tokenizer(inp, return_tensors='pt').to("cuda")
|
23 |
beam_output = model.generate(**input_ids, max_new_tokens=300)
|
24 |
outputText = tokenizer.decode(beam_output[0], skip_special_token=True)
|
@@ -38,4 +38,19 @@ gr.ChatInterface(
|
|
38 |
additional_inputs=[
|
39 |
gr.Textbox(defaultInput, label="Input Text"),
|
40 |
],
|
41 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
model = AutoModelForCausalLM.from_pretrained("ping98k/typhoon-7b-rag-instruct-th", device_map={"": 0})
|
8 |
|
9 |
@spaces.GPU(duration=120)
|
10 |
+
'''def response(instruction, history, inputText):
|
11 |
inp = f"""### Instruction:
|
12 |
{instruction}
|
13 |
|
|
|
18 |
|
19 |
### Response:"""
|
20 |
print(f"Ask: {instruction}")
|
21 |
+
|
22 |
input_ids = tokenizer(inp, return_tensors='pt').to("cuda")
|
23 |
beam_output = model.generate(**input_ids, max_new_tokens=300)
|
24 |
outputText = tokenizer.decode(beam_output[0], skip_special_token=True)
|
|
|
38 |
additional_inputs=[
|
39 |
gr.Textbox(defaultInput, label="Input Text"),
|
40 |
],
|
41 |
+
).launch()'''
|
42 |
+
|
43 |
+
def response(inp):
|
44 |
+
input_ids = tokenizer(inp, return_tensors='pt').to("cuda")
|
45 |
+
beam_output = model.generate(**input_ids, max_new_tokens=300)
|
46 |
+
outputText = tokenizer.decode(beam_output[0], skip_special_token=True)
|
47 |
+
outputText = outputText.replace(inp,"").replace("<s>","").replace("</s>","")
|
48 |
+
|
49 |
+
print(f"Ans: {outputText}")
|
50 |
+
|
51 |
+
return outputText
|
52 |
+
|
53 |
+
gradio_interface = gradio.Interface(
|
54 |
+
fn=response
|
55 |
+
)
|
56 |
+
gradio_interface.launch()
|