asv7j commited on
Commit
4105b8b
1 Parent(s): b0e88c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -1,7 +1,38 @@
1
  from fastapi import FastAPI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  app = FastAPI()
 
 
4
 
 
 
 
 
 
5
  @app.get("/")
6
  def greet_json():
 
 
 
 
 
 
 
 
7
  return {"Hello": "World!"}
 
1
  from fastapi import FastAPI
2
+ import requests
3
+ import json
4
+
5
+ url = "http://127.0.0.1:5000/translate"
6
+ data = {
7
+ "q": "Hello i m here",
8
+ "source": "auto",
9
+ "target": "en",
10
+ "format": "text",
11
+ "alternatives": 3,
12
+ "api_key": ""
13
+ }
14
+ headers = {
15
+ "Content-Type": "application/json"
16
+ }
17
+
18
 
19
  app = FastAPI()
20
+ # Making the POST request
21
+ response = requests.post(url, json=data, headers=headers)
22
 
23
+ # Handling the response
24
+ if response.status_code == 200:
25
+ print(response.json())
26
+ else:
27
+ print(f"Error: {response.status_code} - {response.reason}")
28
  @app.get("/")
29
  def greet_json():
30
+ # Making the POST request
31
+ response = requests.post(url, json=data, headers=headers)
32
+
33
+ # Handling the response
34
+ if response.status_code == 200:
35
+ print(response.json())
36
+ else:
37
+ print(f"Error: {response.status_code} - {response.reason}")
38
  return {"Hello": "World!"}