fede97 commited on
Commit
7a9d08d
1 Parent(s): 2fb04fa

Delete app_old.py

Browse files
Files changed (1) hide show
  1. app_old.py +0 -67
app_old.py DELETED
@@ -1,67 +0,0 @@
1
- # Run the script and open the link in the browser.
2
-
3
- import os
4
- import gradio as gr
5
- import streamlit as st
6
- import torch
7
- from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
8
-
9
- # scratch with latbert tokenizer
10
- CHECKPOINT_PATH= 'scratch_2-nodes_tokenizer_latbert-original_packing_fcocchi/model.safetensors'
11
- CHECKPOINT_PATH= 'itserr/latin_llm_alpha'
12
-
13
- print(f"Loading model from: {CHECKPOINT_PATH}")
14
- tokenizer = AutoTokenizer.from_pretrained(CHECKPOINT_PATH, token=st.secrets["HF_TOKEN"])
15
- model = AutoModelForCausalLM.from_pretrained(CHECKPOINT_PATH, token=st.secrets["HF_TOKEN"])
16
-
17
- description="""
18
- This is a Latin Language Model (LLM) based on GPT-2 and it was trained on a large corpus of Latin texts and can generate text in Latin.
19
- Please enter a prompt in Latin to generate text.
20
- """
21
- title= "(L<sup>3</sup>) - Latin Large Language Model"
22
- article= "hello world ..."
23
- examples= ['Accidere ex una scintilla', 'Audacter calumniare,', 'Consolatium misero comites']
24
- logo_image= 'ITSERR_row_logo.png'
25
-
26
- def generate_text(prompt):
27
- if torch.cuda.is_available(): device = torch.device("cuda")
28
- else:
29
- device = torch.device("cpu")
30
- print("No GPU available")
31
-
32
- print("***** Generate *****")
33
- text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
34
- #generated_text = text_generator(prompt, max_length=100)
35
- generated_text = text_generator(prompt, max_length=50, do_sample=True, temperature=1.0, repetition_penalty=2.0, truncation=True)
36
- return generated_text[0]['generated_text']
37
-
38
- custom_css = """
39
- #logo {
40
- display: block;
41
- margin-left: auto;
42
- margin-right: auto;
43
- width: 512px;
44
- height: 256px;
45
- }
46
- """
47
-
48
- with gr.Blocks(css=custom_css) as demo:
49
- gr.Image(logo_image, elem_id="logo")
50
- gr.Markdown(f"<h1 style='text-align: center;'>{title}</h1>")
51
- gr.Markdown(description)
52
-
53
- with gr.Row():
54
- with gr.Column():
55
- input_text = gr.Textbox(lines=5, placeholder="Enter latin text here...", label="Input Text")
56
- with gr.Column():
57
- output_text = gr.Textbox(lines=5, placeholder="Output text will appear here...", label="Output Text")
58
-
59
- clean_button = gr.Button("Generate Text")
60
- clean_button.click(fn=generate_text, inputs=input_text, outputs=output_text)
61
-
62
- gr.Examples(examples=examples, inputs=input_text)
63
- gr.Markdown(article)
64
-
65
- demo.launch(share=True)
66
- # iface = gr.Interface(fn=generate_text, inputs="text", outputs="text",
67
- # description=description, title=title, examples=examples, article=article)