darshankr commited on
Commit
490cb4b
·
verified ·
1 Parent(s): b6cd2a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -55
app.py CHANGED
@@ -1,58 +1,3 @@
1
- # run.py
2
- import subprocess
3
- import sys
4
- import os
5
-
6
- def main():
7
- # Start Streamlit server only
8
- port = int(os.environ.get("PORT", 7860)) # Hugging Face Spaces uses port 7860
9
- streamlit_process = subprocess.Popen([
10
- sys.executable,
11
- "-m",
12
- "streamlit",
13
- "run",
14
- "app.py",
15
- "--server.port",
16
- str(port),
17
- "--server.address",
18
- "0.0.0.0"
19
- ])
20
-
21
- try:
22
- streamlit_process.wait()
23
- except KeyboardInterrupt:
24
- streamlit_process.terminate()
25
-
26
- if __name__ == "__main__":
27
- main()
28
-
29
- # api.py
30
- from fastapi import FastAPI, HTTPException
31
- from pydantic import BaseModel
32
- from typing import List
33
- from app import translate_text
34
-
35
- app = FastAPI()
36
-
37
- class InputData(BaseModel):
38
- sentences: List[str]
39
- target_lang: str
40
-
41
- @app.get("/health")
42
- async def health_check():
43
- return {"status": "healthy"}
44
-
45
- @app.post("/translate")
46
- async def translate(input_data: InputData):
47
- try:
48
- result = translate_text(
49
- sentences=input_data.sentences,
50
- target_lang=input_data.target_lang
51
- )
52
- return result
53
- except Exception as e:
54
- raise HTTPException(status_code=500, detail=str(e))
55
-
56
  # app.py
57
  import streamlit as st
58
  from fastapi import FastAPI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # app.py
2
  import streamlit as st
3
  from fastapi import FastAPI