Raz Tsook commited on
Commit
14e9c7a
路
1 Parent(s): 5372e99

Fix Gradio compatibility issues - stable versions and simplified interface

Browse files
Files changed (2) hide show
  1. app.py +19 -20
  2. requirements.txt +5 -5
app.py CHANGED
@@ -3,6 +3,7 @@ from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
4
  import uvicorn
5
  import logging
 
6
 
7
  # Configure logging
8
  logging.basicConfig(level=logging.INFO)
@@ -10,8 +11,8 @@ logger = logging.getLogger(__name__)
10
 
11
  # FastAPI app instance
12
  app = FastAPI(
13
- title="Hugging Face API Server",
14
- description="API endpoint for processing requests and returning responses",
15
  version="1.0.0"
16
  )
17
 
@@ -97,14 +98,13 @@ def gradio_interface(json_text):
97
  """Gradio interface wrapper"""
98
  try:
99
  if not json_text.strip():
100
- return "讗谞讗 讛讻谞住 JSON", "{}"
101
 
102
  # Try to parse the JSON
103
- import json
104
  try:
105
  data = json.loads(json_text)
106
  except json.JSONDecodeError:
107
- return "砖讙讬讗讛: JSON 诇讗 转拽讬谉", "{}"
108
 
109
  # Process the data
110
  message = process_any_json(data)
@@ -118,41 +118,40 @@ def gradio_interface(json_text):
118
 
119
  response_json = json.dumps(response, indent=2, ensure_ascii=False)
120
 
121
- return f"转砖讜讘讛 诪讛砖专转:\n{message}\n\n讛讙讬讬住讜谉 砖讛转拽讘诇 讛讜讞讝专 讘转砖讜讘讛", response_json
122
 
123
  except Exception as e:
124
- return f"砖讙讬讗讛: {str(e)}", "{}"
125
 
126
  # Create Gradio interface
127
  with gr.Blocks(title="JSON API Server") as demo:
128
  gr.Markdown("# 馃摗 JSON API Server")
129
- gr.Markdown("砖诇讞 讻诇 JSON 诇砖专转 讜拽讘诇 转砖讜讘讛!")
130
 
131
  with gr.Row():
132
  with gr.Column():
133
- gr.Markdown("### 讛讻谞住 JSON:")
134
- json_input = gr.Code(
135
  label="JSON Input",
136
- language="json",
137
- value='{\n "name": "John",\n "age": 30,\n "city": "Tel Aviv"\n}',
138
- lines=10
139
  )
140
- submit_btn = gr.Button("砖诇讞 诇砖专转", variant="primary")
141
 
142
  with gr.Column():
143
- gr.Markdown("### 转砖讜讘讛 诪讛砖专转:")
144
  output = gr.Textbox(
145
- label="讛讜讚注讛",
146
  lines=4,
147
  interactive=False
148
  )
149
 
150
  gr.Markdown("### JSON Response:")
151
- json_output = gr.Code(
152
- label="转砖讜讘讛 诪诇讗讛 诪讛砖专转",
153
- language="json",
154
  interactive=False,
155
- lines=10
156
  )
157
 
158
  submit_btn.click(
 
3
  from pydantic import BaseModel
4
  import uvicorn
5
  import logging
6
+ import json
7
 
8
  # Configure logging
9
  logging.basicConfig(level=logging.INFO)
 
11
 
12
  # FastAPI app instance
13
  app = FastAPI(
14
+ title="JSON API Server",
15
+ description="API endpoint that accepts any JSON and returns a response",
16
  version="1.0.0"
17
  )
18
 
 
98
  """Gradio interface wrapper"""
99
  try:
100
  if not json_text.strip():
101
+ return "Please enter JSON", "{}"
102
 
103
  # Try to parse the JSON
 
104
  try:
105
  data = json.loads(json_text)
106
  except json.JSONDecodeError:
107
+ return "Error: Invalid JSON format", "{}"
108
 
109
  # Process the data
110
  message = process_any_json(data)
 
118
 
119
  response_json = json.dumps(response, indent=2, ensure_ascii=False)
120
 
121
+ return f"Server Response:\n{message}\n\nYour JSON was received and returned", response_json
122
 
123
  except Exception as e:
124
+ return f"Error: {str(e)}", "{}"
125
 
126
  # Create Gradio interface
127
  with gr.Blocks(title="JSON API Server") as demo:
128
  gr.Markdown("# 馃摗 JSON API Server")
129
+ gr.Markdown("Send any JSON to the server and get a response!")
130
 
131
  with gr.Row():
132
  with gr.Column():
133
+ gr.Markdown("### Enter JSON:")
134
+ json_input = gr.Textbox(
135
  label="JSON Input",
136
+ value='{"name": "John", "age": 30, "city": "Tel Aviv"}',
137
+ lines=5,
138
+ placeholder="Enter your JSON here..."
139
  )
140
+ submit_btn = gr.Button("Send to Server", variant="primary")
141
 
142
  with gr.Column():
143
+ gr.Markdown("### Server Response:")
144
  output = gr.Textbox(
145
+ label="Message",
146
  lines=4,
147
  interactive=False
148
  )
149
 
150
  gr.Markdown("### JSON Response:")
151
+ json_output = gr.Textbox(
152
+ label="Complete Response",
 
153
  interactive=False,
154
+ lines=8
155
  )
156
 
157
  submit_btn.click(
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- gradio>=4.0.0
2
- fastapi>=0.104.0
3
- uvicorn[standard]>=0.24.0
4
- pydantic>=2.0.0
5
- python-multipart>=0.0.6
 
1
+ gradio==4.44.0
2
+ fastapi==0.104.1
3
+ uvicorn[standard]==0.24.0
4
+ pydantic==2.5.0
5
+ python-multipart==0.0.6