abadesalex commited on
Commit
02a9316
1 Parent(s): 76d7ce2
, DELETED
File without changes
FastAPI/app/__pycache__/api.cpython-310.pyc ADDED
Binary file (977 Bytes). View file
 
FastAPI/app/api.py CHANGED
@@ -1,27 +1,35 @@
1
- from fastapi import FastAPI
2
- from fastapi.staticfiles import StaticFiles
3
- from fastapi.responses import FileResponse
4
  from fastapi.middleware.cors import CORSMiddleware
5
-
6
 
7
  app = FastAPI()
8
 
 
9
  origins = [
10
  "http://localhost:3000",
11
- "localhost:3000",
12
- "https://abadesalex-emb-rep.hf.space",
 
13
  ]
14
-
15
  app.add_middleware(
16
  CORSMiddleware,
17
  allow_origins=origins,
18
  allow_credentials=True,
19
  allow_methods=["*"],
20
- allow_headers=["*"]
21
  )
22
 
23
- app.mount("/", StaticFiles(directory="app/build", html=True), name="static")
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- # @app.get("/")
26
- # def index() -> FileResponse:
27
- # return FileResponse(path="/app/build/index.html", media_type="text/html")
 
1
+ from fastapi import FastAPI, Query
 
 
2
  from fastapi.middleware.cors import CORSMiddleware
3
+ from fastapi.staticfiles import StaticFiles
4
 
5
  app = FastAPI()
6
 
7
+ # CORS setup
8
  origins = [
9
  "http://localhost:3000",
10
+ "http://localhost:8000",
11
+ "localhost:8000",
12
+ "https://your-space-name.hf.space",
13
  ]
 
14
  app.add_middleware(
15
  CORSMiddleware,
16
  allow_origins=origins,
17
  allow_credentials=True,
18
  allow_methods=["*"],
19
+ allow_headers=["*"],
20
  )
21
 
22
+ # Mount static files
23
+ app.mount("/static", StaticFiles(directory="app/build", html=True), name="static")
24
+
25
+
26
+ # Define API route
27
+ @app.get("/api/sum_of_lengths")
28
+ def sum_of_lengths(word1: str = Query(...), word2: str = Query(...)):
29
+ return {"sum": len(word1) + len(word2)}
30
+
31
+
32
+ if __name__ == "__main__":
33
+ import uvicorn
34
 
35
+ uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
my-app/src/App.js CHANGED
@@ -1,74 +1,53 @@
1
- import { Button, Grid, TextField } from "@mui/material";
2
- import { useState } from "react";
3
- import "./App.css";
4
 
5
- function App() {
6
- const [message, setMessage] = useState("");
7
  const [wordOne, setWordOne] = useState("");
8
-
9
- const onChangeWordOne = (event) => {
10
- const newWord = event.target.value;
11
- console.log("Word One: ", newWord);
12
- setWordOne(newWord);
13
- };
14
 
15
  const onPressButton = () => {
16
- setMessage('Pau chupapijas');
17
- // console.log("Word One: ", wordOne);
18
- // const url = "http://127.0.0.1:8000/test";
19
- const url = "https://abadesalex-emb-rep.hf.space/test";
20
- // const dataToSend = JSON.stringify({ message: wordOne });
21
- // fetch(url, {
22
- // method: "POST", // Specifying the method
23
- // headers: {
24
- // "Content-Type": "application/json",
25
- // },
26
- // body: dataToSend, // Data must be a stringified JSON
27
- // })
28
- // .then((response) => response.json())
29
- // .then((data) => setMessage(data.Hello))
30
- // .catch((error) => console.error("Error:", error));
 
 
 
 
 
 
 
31
  };
32
 
33
  return (
34
- <>
35
- <Grid container mt={2} mr={2} ml={2} textAlign={"center"} spacing={2}>
36
- <Grid item xs={3}>
37
- <TextField
38
- id="word-one"
39
- label="Word 1"
40
- variant="outlined"
41
- onChange={onChangeWordOne}
42
- fullWidth
43
- />
44
- </Grid>
45
-
46
- <Grid item xs={3}>
47
- <TextField
48
- id="word-two"
49
- label="Word 2"
50
- variant="outlined"
51
- fullWidth
52
- />
53
- </Grid>
54
-
55
- <Grid item xs={3}>
56
- <Button
57
- variant="contained"
58
- color="primary"
59
- fullWidth
60
- sx={{ height: "100%" }}
61
- onClick={onPressButton}
62
- >
63
- Compare Embedding
64
- </Button>
65
- </Grid>
66
- </Grid>
67
- <Grid item textAlign={"center"}>
68
- <h1>{message}</h1>
69
- </Grid>
70
- </>
71
  );
72
- }
73
 
74
  export default App;
 
1
+ import React, { useState } from "react";
 
 
2
 
3
+ const App = () => {
 
4
  const [wordOne, setWordOne] = useState("");
5
+ const [wordTwo, setWordTwo] = useState("");
6
+ const [message, setMessage] = useState("");
 
 
 
 
7
 
8
  const onPressButton = () => {
9
+ // Construct the URL with query parameters
10
+ //const url = `https://abadesalex-emb-rep.hf.space/api/sum_of_lengths?word1=${wordOne}&word2=${wordTwo}`;
11
+ const url = `http://localhost:8000/api/sum_of_lengths?word1=${wordOne}&word2=${wordTwo}`;
12
+
13
+ fetch(url, {
14
+ method: "GET",
15
+ headers: {
16
+ "Content-Type": "application/json",
17
+ },
18
+ })
19
+ .then((response) => response.json())
20
+ .then((data) => {
21
+ if (data.sum !== undefined) {
22
+ setMessage(`Sum of lengths: ${data.sum}`);
23
+ } else {
24
+ setMessage("Error: Unexpected response");
25
+ }
26
+ })
27
+ .catch((error) => {
28
+ console.error("Error:", error);
29
+ setMessage("Error: Failed to fetch data");
30
+ });
31
  };
32
 
33
  return (
34
+ <div>
35
+ <input
36
+ type="text"
37
+ value={wordOne}
38
+ onChange={(e) => setWordOne(e.target.value)}
39
+ placeholder="First Word"
40
+ />
41
+ <input
42
+ type="text"
43
+ value={wordTwo}
44
+ onChange={(e) => setWordTwo(e.target.value)}
45
+ placeholder="Second Word"
46
+ />
47
+ <button onClick={onPressButton}>Submit</button>
48
+ <p>{message}</p>
49
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  );
51
+ };
52
 
53
  export default App;
prev.tsx ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Button, Grid, TextField } from "@mui/material";
2
+ import { useState } from "react";
3
+ import "./App.css";
4
+
5
+ function App() {
6
+ const [message, setMessage] = useState("");
7
+ const [wordOne, setWordOne] = useState("");
8
+
9
+ const onChangeWordOne = (event) => {
10
+ const newWord = event.target.value;
11
+ console.log("Word One: ", newWord);
12
+ setWordOne(newWord);
13
+ };
14
+
15
+ const onPressButton = () => {
16
+ setMessage("Pau chupapijas");
17
+ // console.log("Word One: ", wordOne);
18
+ // const url = "http://127.0.0.1:8000/test";
19
+ const url = "https://abadesalex-emb-rep.hf.space/test";
20
+ const dataToSend = JSON.stringify({ message: wordOne });
21
+ fetch(url, {
22
+ method: "POST", // Specifying the method
23
+ headers: {
24
+ "Content-Type": "application/json",
25
+ },
26
+ body: dataToSend, // Data must be a stringified JSON
27
+ })
28
+ .then((response) => response.json())
29
+ .then((data) => setMessage(data.Hello))
30
+ .catch((error) => console.error("Error:", error));
31
+ };
32
+
33
+ return (
34
+ <>
35
+ <Grid container mt={2} mr={2} ml={2} textAlign={"center"} spacing={2}>
36
+ <Grid item xs={3}>
37
+ <TextField
38
+ id="word-one"
39
+ label="Word 1"
40
+ variant="outlined"
41
+ onChange={onChangeWordOne}
42
+ fullWidth
43
+ />
44
+ </Grid>
45
+
46
+ <Grid item xs={3}>
47
+ <TextField
48
+ id="word-two"
49
+ label="Word 2"
50
+ variant="outlined"
51
+ fullWidth
52
+ />
53
+ </Grid>
54
+
55
+ <Grid item xs={3}>
56
+ <Button
57
+ variant="contained"
58
+ color="primary"
59
+ fullWidth
60
+ sx={{ height: "100%" }}
61
+ onClick={onPressButton}
62
+ >
63
+ Compare Embedding
64
+ </Button>
65
+ </Grid>
66
+ </Grid>
67
+ <Grid item textAlign={"center"}>
68
+ <h1>{message}</h1>
69
+ </Grid>
70
+ </>
71
+ );
72
+ }
73
+
74
+ export default App;