fede97 commited on
Commit
2868eeb
1 Parent(s): dc5722c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ retutn 'hello world'
32
+
33
+ #print("***** Generate *****")
34
+ #text_generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=device)
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.Markdown(f"<h1 style='text-align: center;'>{title}</h1>")
50
+
51
+ with gr.Row():
52
+ with gr.Column():
53
+ input_text = gr.Textbox(lines=5, placeholder="Enter latin text here...", label="Input Text")
54
+ with gr.Column():
55
+ output_text = gr.Textbox(lines=5, placeholder="Output text will appear here...", label="Output Text")
56
+
57
+ clean_button = gr.Button("Generate Text")
58
+ clean_button.click(fn=generate_text, inputs=input_text, outputs=output_text)
59
+
60
+ demo.launch(share=True)