Nishant51 commited on
Commit
34b15a6
·
verified ·
1 Parent(s): 96a198f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ #1. Load the AI Brain (We are using a free one called GPT-2)
5
+ print("Loading AI...")
6
+ generator = pipeline('text-generation', model='gpt2')
7
+
8
+ #2 Define the function (what happens when you ask it)
9
+ def ask_brain(question);
10
+ #this tells the AI to generate an answer
11
+ result = generator(question, max_length= 100, num_return_sequences=1)
12
+ answer = result[0]
13
+ ['generated_text']
14
+ #we return the answer to the user return answer
15
+
16
+ #3 Launch the app (this cerates the API)
17
+ iface = gr.Interface(fn=ask_brain, inputs="text", output="text")
18
+ iface.launch()