elsamueldev commited on
Commit
386e947
1 Parent(s): a0c6903

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +18 -0
  2. main.py +51 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -ms /bin/bash user
4
+
5
+ USER user
6
+
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH
9
+
10
+ WORKDIR $HOME/code
11
+
12
+ COPY ./requirements.txt $HOME/code/requirements.txt
13
+
14
+ RUN pip install --no-cache-dir --upgrade -r $HOME/code/requirements.txt
15
+
16
+ COPY --chown=user . $HOME/code
17
+
18
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import flet as ft
2
+ from flet import TextField, ElevatedButton
3
+ from flet_core import ControlEvent
4
+ import flet_fastapi
5
+
6
+ async def main(page: ft.Page) -> None:
7
+ page.title = "Some form"
8
+
9
+ dlg = ft.AlertDialog(
10
+ title=ft.Text("This doesn't work yet!"), on_dismiss=lambda e: print("Dialog dismissed!")
11
+ )
12
+
13
+ async def open_dlg(e: ControlEvent):
14
+ page.dialog = dlg
15
+ dlg.open = True
16
+ await page.update_async()
17
+
18
+ question: TextField = TextField(label="Question", text_align=ft.TextAlign.LEFT, width=200)
19
+ answer: TextField = TextField(label="Answer", text_align=ft.TextAlign.LEFT, width=200)
20
+
21
+ button_submit: ElevatedButton = ElevatedButton(text="Send", disabled=True)
22
+
23
+ async def validate(e: ControlEvent) -> None:
24
+ if all((question.value, answer.value)):
25
+ button_submit.disabled = False
26
+ else:
27
+ button_submit.disabled = True
28
+
29
+ await page.update_async()
30
+
31
+ async def submit(e: ControlEvent) -> None:
32
+ await open_dlg(e)
33
+
34
+ question.on_change = validate
35
+ answer.on_change = validate
36
+ button_submit.on_click = submit
37
+
38
+
39
+ await page.add_async(
40
+ ft.Container(question, alignment=ft.alignment.center)
41
+ )
42
+
43
+ await page.add_async(
44
+ ft.Container(answer, alignment=ft.alignment.center)
45
+ )
46
+
47
+ await page.add_async(
48
+ ft.Container(button_submit, alignment=ft.alignment.center)
49
+ )
50
+
51
+ app = flet_fastapi.app(main) # type: ignore
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ uvicorn
2
+ fastapi
3
+ flet
4
+ flet-fastapi