wb-droid commited on
Commit
fb839eb
·
1 Parent(s): 7629e6e

first commit.

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -0
  2. app.py +55 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10.9
2
+
3
+ COPY . .
4
+
5
+ WORKDIR /
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /requirements.txt
8
+
9
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8443"]
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ import gradio as gr
3
+ import httpx
4
+ import os
5
+
6
+
7
+ API_TOKEN = os.environ.get('HUGGINGFACE_API_KEY')
8
+ HF_API_KEY = API_TOKEN
9
+
10
+ TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
11
+ BASE_URL = f"https://api.telegram.org/bot{TOKEN}"
12
+
13
+ CUSTOM_PATH = "/gradio"
14
+ app = FastAPI()
15
+
16
+ client = httpx.AsyncClient()
17
+
18
+ @app.get("/")
19
+ def read_main():
20
+ return {"message": "This is your main app"}
21
+
22
+ @app.post("/")
23
+ def read_main():
24
+ return {"message": "This is webhook"}
25
+
26
+ @app.post("/webhook")
27
+ async def webhook(req: Request):
28
+ data = await req.json()
29
+ chat_id = data['message']['chat']['id']
30
+ text = data['message']['text']
31
+
32
+ await client.get(f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}")
33
+
34
+ return data
35
+
36
+ def flip_text(x):
37
+ return x[::-1]
38
+
39
+ with gr.Blocks() as demo:
40
+
41
+ gr.Markdown(
42
+ """
43
+ # Flip Text!
44
+ Start typing below to see the output.
45
+ """
46
+ )
47
+
48
+ input = gr.Textbox(placeholder="Flip this text")
49
+ output = gr.Textbox()
50
+
51
+ input.change(fn=flip_text, inputs=input, outputs=output)
52
+
53
+ gr.mount_gradio_app(app, demo, path=CUSTOM_PATH)
54
+
55
+ #uvicorn.run(app, port=8443)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ httpx