hyejoo commited on
Commit
27b1577
1 Parent(s): 0be7395

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -1,4 +1,25 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  gr.load("models/yeye776/t5-OndeviceAI-HomeIoT").launch()
4
  # iface = gradio.Interface(fn=pipe_home, inputs="text", outputs="text")
 
1
  import gradio as gr
2
+ from typing import List
3
+
4
+ def prepare_input(question: str):
5
+ inputs = f"{prompt} {question}"
6
+ input_ids = tokenizer(inputs, max_length=700, return_tensors="pt").input_ids
7
+ return input_ids
8
+
9
+ def inference(question: str) -> str:
10
+ input_data = prepare_input(question=question)
11
+ input_data = input_data.to(model.device)
12
+ outputs = model.generate(inputs=input_data, num_beams=10, top_k=10, max_length=1024)
13
+
14
+ result = tokenizer.decode(token_ids=outputs[0], skip_special_tokens=True)
15
+
16
+ print("question:", question, "answer:", result)
17
+ return result
18
+
19
+ test_id = 1160
20
+ # 거실조명1 꺼주세요 "Home:거실,NickName:조명1,ActionID:1061,Value:없음"
21
+ print("model result:", inference(dataset_finetuning["train"][test_id]["Q"]))
22
+ print("real result:", dataset_finetuning["train"][test_id]["C"])
23
 
24
  gr.load("models/yeye776/t5-OndeviceAI-HomeIoT").launch()
25
  # iface = gradio.Interface(fn=pipe_home, inputs="text", outputs="text")