File size: 624 Bytes
34b15a6 4845085 34b15a6 4845085 c7a3ad9 4845085 c7a3ad9 4845085 c7a3ad9 4845085 c7a3ad9 4845085 c7a3ad9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import gradio as gr
from transformers import pipeline
#1.Load the AI Brain (We are using a free one called GPT-2)
print("Loading AI...")
generator = pipeline('text-generation', model='gpt2')
#2.Define the function (what happens when you ask it)
def ask_brain(question):
#This tells the AI to generate an answer
result = generator(question, max_length = 100, num_return_sequences=1)
answer = result[0]
['generated_text']
#We return the answer to the user return answer
#3. Launch the App(This createes the API)
iface = gr.Interface(fn=ask_brain, inputs="text", output="text")
iface.launch() |