Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip install transformers
|
2 |
+
pip install datasets
|
3 |
+
pip install gradio
|
4 |
+
sudo apt-get install git-lfs
|
5 |
+
|
6 |
+
import torch
|
7 |
+
import pandas as pd
|
8 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, AutoModelForSequenceClassification, TrainingArguments
|
9 |
+
import gradio as gr
|
10 |
+
import torch.nn.functional as F
|
11 |
+
|
12 |
+
from datasets import load_dataset
|
13 |
+
dataset = load_dataset("bananabot/engMollywoodSummaries")
|
14 |
+
dataset
|
15 |
+
|
16 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
+
|
18 |
+
model_name = "EleutherAI/gpt-neo-125M"
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
20 |
+
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
|
21 |
+
|
22 |
+
max_length=123
|
23 |
+
input_txt = "This malayalam movie is about"
|
24 |
+
n_steps = 8
|
25 |
+
|
26 |
+
input_ids = tokenizer(input_txt, return_tensors="pt")["input_ids"].to(device)
|
27 |
+
output = model.generate(input_ids, max_length=max_length, num_beams=5, do_sample=True, no_repeat_ngram_size=2, temperature=1.37, top_k=69, top_p=0.96)
|
28 |
+
print(tokenizer.decode(output[0]))
|
29 |
+
|
30 |
+
generator = gr.Interface.load("models/EleutherAI/gpt-neo-125M")
|
31 |
+
translator = gr.Interface.load("models/Helsinki-NLP/opus-mt-en-ml")
|
32 |
+
gr.Series(generator, translator).launch() # this demo generates text, then translates it to Malayalam, and outputs the final result.
|