Nexchan commited on
Commit
9baa4cb
·
verified ·
1 Parent(s): bc6bd3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -34
app.py CHANGED
@@ -1,11 +1,8 @@
1
- from flask import Flask, request, jsonify
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
  import json
5
 
6
- app = Flask(__name__)
7
-
8
- # Inisialisasi Gradio dan HuggingFace client
9
  client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
10
 
11
  def chat_llama(chat_history):
@@ -48,8 +45,7 @@ def process_json(json_input):
48
  return json.dumps(chat_history, indent=2), ""
49
 
50
  # Definisikan antarmuka Gradio
51
- gr_interface = gr.Blocks()
52
- with gr_interface:
53
  with gr.Row():
54
  with gr.Column():
55
  chatbot = gr.Chatbot()
@@ -66,31 +62,5 @@ with gr_interface:
66
  process_btn = gr.Button("Process JSON", variant='primary')
67
  process_btn.click(fn=process_json, inputs=json_input, outputs=[json_output])
68
 
69
- @app.route("/", methods=["GET"])
70
- def home():
71
- return gr_interface.launch(inline=True, share=False)
72
-
73
- @app.route("/chat_llama", methods=["POST"])
74
- def chat_llama_endpoint():
75
- data = request.json
76
- chat_history = data.get('chat_history', [])
77
- response = chat_llama(chat_history)
78
- return jsonify(response)
79
-
80
- @app.route("/chat_mem", methods=["POST"])
81
- def chat_mem_endpoint():
82
- data = request.json
83
- message = data.get('message', '')
84
- chat_history = data.get('chat_history', [])
85
- response = chat_mem(message, chat_history)
86
- return jsonify(response)
87
-
88
- @app.route("/process_json", methods=["POST"])
89
- def process_json_endpoint():
90
- data = request.json
91
- json_input = data.get('json_input', '')
92
- response = process_json(json_input)
93
- return jsonify(response)
94
-
95
- if __name__ == "__main__":
96
- app.run(host="0.0.0.0", port=7860)
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import json
4
 
5
+ # Inisialisasi HuggingFace client
 
 
6
  client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
7
 
8
  def chat_llama(chat_history):
 
45
  return json.dumps(chat_history, indent=2), ""
46
 
47
  # Definisikan antarmuka Gradio
48
+ with gr.Blocks() as demo:
 
49
  with gr.Row():
50
  with gr.Column():
51
  chatbot = gr.Chatbot()
 
62
  process_btn = gr.Button("Process JSON", variant='primary')
63
  process_btn.click(fn=process_json, inputs=json_input, outputs=[json_output])
64
 
65
+ # Jalankan antarmuka Gradio dan sediakan API
66
+ demo.launch(server_name="0.0.0.0", server_port=7860, share=False)