Spaces:
Sleeping
Sleeping
manjunathtl
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
def generate_kannada_text(prompt):
|
6 |
+
model_name = "Tensoic/Kan-LLaMA-7B-SFT-v0.1"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
9 |
+
|
10 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
11 |
+
|
12 |
+
output = model.generate(
|
13 |
+
input_ids,
|
14 |
+
max_length=150,
|
15 |
+
num_beams=5,
|
16 |
+
no_repeat_ngram_size=2,
|
17 |
+
top_k=50,
|
18 |
+
top_p=0.95,
|
19 |
+
length_penalty=0.8
|
20 |
+
)
|
21 |
+
|
22 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
23 |
+
return generated_text
|
24 |
+
|
25 |
+
def main():
|
26 |
+
st.title("Kannada Text Generation App")
|
27 |
+
|
28 |
+
# User input prompt
|
29 |
+
prompt = st.text_area("Enter a prompt in Kannada:")
|
30 |
+
|
31 |
+
# Generate Kannada text
|
32 |
+
if st.button("Generate Text"):
|
33 |
+
generated_text = generate_kannada_text(prompt)
|
34 |
+
st.subheader("Generated Kannada Text:")
|
35 |
+
st.write(generated_text)
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
main()
|