Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
|
6 |
+
model_name = "codellama/CodeLlama-7b-Python-hf"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else 'cpu')
|
11 |
+
model = model.to(device)
|
12 |
+
|
13 |
+
# prompt = st.text_area("Enter your prompt:")
|
14 |
+
|
15 |
+
|
16 |
+
# def translate_text(text, source_lang, target_lang):
|
17 |
+
# tokenizer.src_lang = source_lang
|
18 |
+
# encoded_text = tokenizer(text, return_tensors="pt").to(device)
|
19 |
+
|
20 |
+
# generated_tokens = model.generate(**encoded_text, forced_bos_token_id=tokenizer.lang_code_to_id[target_lang])
|
21 |
+
|
22 |
+
# #Decode the output
|
23 |
+
# translated_text = tokenizer.decode(generated_tokens[0], skip_special_tokens=True)
|
24 |
+
# return translated_text
|
25 |
+
|
26 |
+
|
27 |
+
st.markdown("### Python Code Helper")
|
28 |
+
# source_language = ''
|
29 |
+
# target_language = ''
|
30 |
+
# source = st.sidebar.selectbox('Source Language', languages)
|
31 |
+
# if source:
|
32 |
+
# source_language = lang_dict.get(source)
|
33 |
+
# st.write(source_language)
|
34 |
+
|
35 |
+
# target = st.sidebar.selectbox('Target Language', languages)
|
36 |
+
# if target:
|
37 |
+
# target_language = lang_dict.get(target)
|
38 |
+
# st.write(target_language)
|
39 |
+
|
40 |
+
with st.form(key="myForm"):
|
41 |
+
prompt = st.text_area("Enter your Prompt")
|
42 |
+
submit = st.form_submit_button("Submit", type='primary')
|
43 |
+
|
44 |
+
if submit and prompt:
|
45 |
+
with st.spinner("Generating Response"):
|
46 |
+
response = model.invoke(prompt)
|
47 |
+
st.write(response)
|
48 |
+
|