subham1707 commited on
Commit
2ef7239
Β·
1 Parent(s): a5e1d2a

application deployed

Browse files
Files changed (2) hide show
  1. app.py +39 -4
  2. requirements.txt +14 -0
app.py CHANGED
@@ -1,7 +1,42 @@
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
1
+ #import gradio as gr
2
+
3
+ #def greet(name):
4
+ # return "Hello " + name + "!!"
5
+
6
+ #demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ #demo.launch()
8
+
9
+ #######################
10
+
11
  import gradio as gr
12
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
13
+
14
+ model_id = "codellama/CodeLlama-7b-Instruct-hf"
15
+
16
+ # Load the tokenizer and model
17
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
18
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
19
+
20
+ # Use text-generation pipeline
21
+ generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
22
+
23
+ # Define the function to handle the conversion
24
+ def convert_python_to_r(python_code):
25
+ prompt = f"""### Task:
26
+ Convert the following Python code to equivalent R code.
27
+
28
+ ### Python code:
29
+ {python_code}
30
 
31
+ ### R code:"""
32
+ result = generator(prompt, max_length=1024, temperature=0.2, num_return_sequences=1)
33
+ return result[0]['generated_text']
34
 
35
+ # Gradio Interface
36
+ gr.Interface(
37
+ fn=convert_python_to_r,
38
+ inputs=gr.Textbox(lines=10, placeholder="Paste your Python code here..."),
39
+ outputs="text",
40
+ title="Python to R Code Converter using CodeLlama",
41
+ description="Enter Python code, and this tool will convert it into equivalent R code using CodeLlama Instruct model."
42
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #transformers
2
+ #torch
3
+ #requests
4
+ #Pillow
5
+ #open_clip_torch
6
+ #ftfy
7
+
8
+ transformers
9
+ torch
10
+ gradio
11
+ accelerate
12
+
13
+ # This is only needed for local deployment
14
+ gradio