Noah-Wang commited on
Commit
36d889f
·
1 Parent(s): 9318973

chatgpt type app

Browse files
Files changed (1) hide show
  1. app.py +39 -4
app.py CHANGED
@@ -1,7 +1,42 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import requests
3
 
4
+ API_URL = "https://koj7q6d5hdy4h5tm.us-east-1.aws.endpoints.huggingface.cloud"
5
+ headers = {
6
+ "Accept": "application/json",
7
+ "Authorization": "Bearer hf_XXXXX",
8
+ "Content-Type": "application/json"
9
+ }
10
 
11
+ def query(payload):
12
+ response = requests.post(API_URL, headers=headers, json=payload)
13
+ return response.json()
14
+
15
+ def process_file_or_image(file):
16
+ if file is None:
17
+ return "No file provided!"
18
+
19
+ # Assuming API accepts file content as input
20
+ with open(file.name, "rb") as f:
21
+ file_content = f.read()
22
+
23
+ # Sending the content to the API
24
+ response = query({
25
+ "inputs": file_content.decode("utf-8", errors="ignore"), # Adjust as per API expectations
26
+ "parameters": {}
27
+ })
28
+
29
+ return response
30
+
31
+ # Gradio app
32
+ with gr.Blocks() as app:
33
+ gr.Markdown("# File/Image Upload App")
34
+ gr.Markdown("Upload an image or file and send its content to the API.")
35
+
36
+ file_input = gr.File(label="Upload an Image or File", type="file")
37
+ output = gr.JSON(label="API Response")
38
+
39
+ process_button = gr.Button("Process")
40
+ process_button.click(process_file_or_image, inputs=file_input, outputs=output)
41
+
42
+ app.launch()