speqtr commited on
Commit
1f9bece
1 Parent(s): f0627b1

basic ui using fastapi + uvicorn

Browse files
introduck/api.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from introduck.routes import create_base_route
3
+
4
+
5
+ def create_api() -> FastAPI:
6
+ api: FastAPI = FastAPI()
7
+
8
+ api.mount("/", create_base_route(title="Introduck"))
9
+
10
+ return api
introduck/routes.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from fastapi import FastAPI
4
+ from gradio.routes import App as GradioApp
5
+
6
+
7
+ def _analyze_message(sender: str, recipients: str, subject: str, message: str):
8
+ input_message: str = f"""
9
+ From: {sender or '<empty>'}
10
+ To: {recipients or '<empty>'}
11
+ Subject: {subject or '<empty>'}
12
+
13
+ {message or ''}
14
+ """
15
+
16
+ contacts: list = [["John Doe", "Acme Corp.", "john@example.com", "ai, nn"]]
17
+
18
+ acceptance_reply: str = "Good!"
19
+
20
+ rejection_reply: str = "Not interested :("
21
+
22
+ return input_message, contacts, acceptance_reply, rejection_reply
23
+
24
+
25
+ def _use_message_template() -> (str, str):
26
+ subject: str = "Could you make an intro?"
27
+
28
+ message: str = """\
29
+ Hey,
30
+
31
+ hope you are doing well! :-)
32
+
33
+ Could you, please, make me an intro to one of them?
34
+ - <person1@example.com>
35
+ - <person2@acme.corp>
36
+ - etc.
37
+
38
+ Relevant info:
39
+ - <add your one sentence summary here>;
40
+ - Raising <add your fundraising amount here>;
41
+ - We are backed by <add your existing investor names here>;
42
+ - Team:
43
+ + <add team members>
44
+ - Traction highlights:
45
+ + <highlights list>
46
+
47
+ Best,
48
+ <your name>"""
49
+
50
+ return subject, message
51
+
52
+
53
+ def create_base_route(title: str = "") -> FastAPI:
54
+ with gr.Blocks(analytics_enabled=False, title=title) as base_blocks:
55
+ gr.Markdown(f"""\
56
+ # Introduck
57
+ ## All introductions are better with an AI-powered 🦆
58
+ No new tools. No complex setup. No hassle.
59
+ """)
60
+
61
+ with gr.Group():
62
+ email_sender_input: gr.Textbox = gr.Textbox(
63
+ label="From:",
64
+ lines=1,
65
+ max_lines=1,
66
+ placeholder="founder@acme.com")
67
+
68
+ email_recipients_input: gr.Textbox = gr.Textbox(
69
+ label="To:",
70
+ lines=1,
71
+ max_lines=1,
72
+ placeholder="vc@example.com")
73
+
74
+ email_subject_input: gr.Textbox = gr.Textbox(
75
+ show_label=False,
76
+ lines=1,
77
+ max_lines=1,
78
+ placeholder="Subject...",
79
+ interactive=True)
80
+
81
+ email_message_input: gr.Textbox = gr.Textbox(
82
+ show_label=False,
83
+ lines=5,
84
+ max_lines=42,
85
+ placeholder="Type a message...",
86
+ interactive=True)
87
+
88
+ # TODO: Add support for attached files.
89
+ # email_attachments_input: gr.File = gr.File(
90
+ # label="Attachments:",
91
+ # file_count="multiple")
92
+
93
+ with gr.Row():
94
+ email_template_button: gr.Button = gr.Button(
95
+ value="Use template",
96
+ variant="secondary")
97
+
98
+ email_template_button.click(
99
+ fn=_use_message_template,
100
+ inputs=[],
101
+ outputs=[email_subject_input, email_message_input])
102
+
103
+ email_submit_button: gr.Button = gr.Button(
104
+ value="Submit",
105
+ variant="primary")
106
+
107
+ with gr.Tabs(selected="default"):
108
+ with gr.TabItem(label="Input"):
109
+ rfc822_output: gr.HighlightedText = gr.HighlightedText(
110
+ label="RFC822 message:",
111
+ show_legend=False)
112
+
113
+ with gr.TabItem(label="Contacts", id="default"):
114
+ contacts_table_headers: list[str] = [
115
+ "Name",
116
+ "Company",
117
+ "Email",
118
+ "NOTE"]
119
+
120
+ contacts_output: gr.Dataframe = gr.Dataframe(
121
+ headers=contacts_table_headers,
122
+ max_cols=len(contacts_table_headers),
123
+ max_rows=16)
124
+
125
+ with gr.TabItem(label="Accept request"):
126
+ acceptance_template_output: gr.Textbox = gr.Textbox(
127
+ label="Use this message to accept an intro request:",
128
+ interactive=True)
129
+
130
+ with gr.TabItem(label="Decline request"):
131
+ rejection_template_output: gr.Textbox = gr.Textbox(
132
+ label="Use this message to decline an intro request:",
133
+ interactive=True)
134
+
135
+ email_submit_button.click(
136
+ fn=_analyze_message,
137
+ inputs=[
138
+ email_sender_input,
139
+ email_recipients_input,
140
+ email_subject_input,
141
+ email_message_input],
142
+ outputs=[
143
+ rfc822_output,
144
+ contacts_output,
145
+ acceptance_template_output,
146
+ rejection_template_output])
147
+
148
+ gr.Markdown("## FAQ")
149
+
150
+ with gr.Group():
151
+ with gr.Accordion("Is it cool?"):
152
+ gr.Markdown("Yes!")
153
+
154
+ with gr.Accordion("Is it free?"):
155
+ gr.Markdown("Yes!")
156
+
157
+ gr.Markdown("""\
158
+ [Contact us](#)&nbsp;/&nbsp;
159
+ [Terms of Service](#)&nbsp;/&nbsp;
160
+ [Privacy Policy](#)
161
+ """)
162
+
163
+ gr.Markdown("**&copy;** Introduck, 2022")
164
+
165
+ base_route = GradioApp.create_app(blocks=base_blocks)
166
+
167
+ # TODO: overwrite /favicon.ico
168
+
169
+ return base_route
introduck_tests/README.md ADDED
@@ -0,0 +1 @@
 
1
+ # Introduck Tests
main.py CHANGED
@@ -1,9 +1,22 @@
1
- import gradio as gr
2
 
 
3
 
4
- def greet(name):
5
- return "Hello, " + name + "!!!"
 
 
6
 
 
7
 
8
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- iface.launch()
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
 
3
+ """Main entry point for application
4
 
5
+ Usage examples:
6
+ - gunicorn main:app -w 1 -k uvicorn.workers.UvicornWorker <...other options>
7
+ - uvicorn --reload main:app <...other options>
8
+ """
9
 
10
+ import os
11
 
12
+ from fastapi import FastAPI
13
+ from introduck.api import create_api
14
+ from subprocess import run
15
+
16
+ app: FastAPI = create_api()
17
+
18
+ if __name__ == "__main__":
19
+ if os.getenv("HUGGINGFACE_RUNTIME", 0) == 1:
20
+ # Hugging Face Space served with FastAPI and Uvicorn:
21
+ # https://huggingface.co/spaces/templates/fastapi-uvicorn
22
+ run("uvicorn --reload --host 0.0.0.0 --port 7860 main:app", shell=True)
requirements.txt CHANGED
@@ -1 +1,3 @@
 
1
  gradio==3.3.1 # keep in sync with version from README.md metadata
 
1
+ fastapi[all]
2
  gradio==3.3.1 # keep in sync with version from README.md metadata
3
+ uvicorn[standard]