Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install gradio transformers torch")
|
3 |
+
|
4 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
model = T5ForConditionalGeneration.from_pretrained("./Ruttoni_AI")
|
8 |
+
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-base")
|
9 |
+
|
10 |
+
print("Model loaded!")
|
11 |
+
# Generate a summary using the trained model
|
12 |
+
def generate_summary(input_text):
|
13 |
+
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
14 |
+
outputs = model.generate(input_ids)
|
15 |
+
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return summary
|
17 |
+
|
18 |
+
ai = gr.Interface(fn=generate_summary, inputs="text", outputs="text")
|
19 |
+
|
20 |
+
ai.launch()
|
21 |
+
|
22 |
+
print("Interface Started!")
|