| 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() |