plannist commited on
Commit
f9c8470
·
1 Parent(s): a378469
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -27,15 +27,28 @@ def chat_fn(prompt):
27
  return output
28
  except Exception as e:
29
  return [f"Error: {str(e)}"]
 
 
30
  with gr.Blocks() as demo:
31
- gr.Markdown("### 🐯 KoAlpaca Chatbot")
32
- inp = gr.Textbox(label="Input")
33
- out = gr.Textbox(label="Output")
34
- btn = gr.Button("Submit")
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- btn.click(fn=chat_fn, inputs=inp, outputs=out)
 
37
 
38
- # API endpoint 등록
39
- demo.api(chat_fn, inputs=gr.Textbox(label="prompt"), outputs=gr.Textbox(), name="predict")
40
-
41
- demo.launch(share=False)
 
27
  return output
28
  except Exception as e:
29
  return [f"Error: {str(e)}"]
30
+
31
+
32
  with gr.Blocks() as demo:
33
+ with gr.Row():
34
+ input_box = gr.Textbox(label="Prompt", lines=2)
35
+ with gr.Row():
36
+ output_box = gr.Textbox(label="Response")
37
+
38
+ btn = gr.Button("Generate")
39
+ btn.click(chat_fn, inputs=input_box, outputs=output_box)
40
+
41
+ # ✅ Hugging Face Spaces의 API 요청용 endpoint 정의
42
+ gr.Examples(
43
+ examples=["안녕?", "한국에 대해 말해줘"],
44
+ inputs=input_box
45
+ )
46
+
47
+ demo.load(chat_fn, inputs=input_box, outputs=output_box)
48
 
49
+ # API endpoint로 사용할 Interface 객체 등록
50
+ api_demo = gr.Interface(fn=chat_fn, inputs="text", outputs="text", name="predict")
51
 
52
+ if __name__ == "__main__":
53
+ demo.queue()
54
+ api_demo.launch(share=False)