File size: 918 Bytes
97835c2
21690c9
 
3955fe2
97835c2
ff0aea3
2c2975c
97835c2
21690c9
fde33e1
2c2975c
fde33e1
 
 
 
 
 
 
 
2c2975c
 
 
 
 
fde33e1
de6be74
97835c2
fde33e1
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
import torch
import spaces
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("ping98k/typhoon-7b-rag-instruct-th")
model = AutoModelForCausalLM.from_pretrained("ping98k/typhoon-7b-rag-instruct-th")

@spaces.GPU(duration=120)
def response(instruction, history, inputText):
    inp = f"""### Instruction:
{instruction}

### Input:
=======START OF DOCUMENT=======
{inputText}
=======END OF DOCUMENT=======

### Response:"""

    input_ids = tokenizer(inp, return_tensors='pt').to("cuda")
    beam_output = model.generate(**input_ids)
    outputText = tokenizer.decode(beam_output[0], skip_special_token=True)
    #output = output.replace(inp,"").replace("<s>","").replace("</s>","")
    
    return outputText

gr.ChatInterface(
    response,
    additional_inputs=[
        gr.Textbox("You are helpful AI.", label="Input Text"),
    ],
).launch()