Spaces:
Runtime error
Runtime error
Commit
·
f5ccba2
1
Parent(s):
67b6e62
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,32 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
"""
|
| 8 |
-
# You can specify the programming language here
|
| 9 |
-
# based on the user's choice or default to a specific language.
|
| 10 |
-
language = "Python" # Example: defaulting to Python
|
| 11 |
-
|
| 12 |
-
# Your code generation logic goes here
|
| 13 |
-
generated_code = generate_code(code, language) # Replace with your code generation function
|
| 14 |
-
|
| 15 |
-
return generated_code
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
generated_code = f"Generated {language} code: {code}"
|
| 23 |
return generated_code
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
outputs = gr.outputs.Textbox(label="Generated code")
|
| 28 |
-
|
| 29 |
-
interface = gr.Interface(
|
| 30 |
fn=code_generation,
|
| 31 |
-
inputs=inputs,
|
| 32 |
-
outputs=outputs,
|
| 33 |
title="Gardio App",
|
| 34 |
description="An app that generates code based on user input.",
|
| 35 |
examples=[
|
| 36 |
["Example input code snippet"],
|
| 37 |
["Another example input code snippet"],
|
| 38 |
],
|
| 39 |
-
allow_screenshot=True
|
| 40 |
)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 4 |
|
| 5 |
+
# Load the model and tokenizer
|
| 6 |
+
model_name = "abacaj/Replit-v2-CodeInstruct-3B-ggml"
|
| 7 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
| 8 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Define the code generation function
|
| 11 |
+
def code_generation(code):
|
| 12 |
+
inputs = tokenizer.encode(code, return_tensors="pt")
|
| 13 |
+
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
|
| 14 |
+
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 15 |
return generated_code
|
| 16 |
|
| 17 |
+
# Create the Gradio interface
|
| 18 |
+
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
| 19 |
fn=code_generation,
|
| 20 |
+
inputs=gr.inputs.Textbox(lines=10, label="Enter your code"),
|
| 21 |
+
outputs=gr.outputs.Textbox(label="Generated code"),
|
| 22 |
title="Gardio App",
|
| 23 |
description="An app that generates code based on user input.",
|
| 24 |
examples=[
|
| 25 |
["Example input code snippet"],
|
| 26 |
["Another example input code snippet"],
|
| 27 |
],
|
| 28 |
+
allow_screenshot=True
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# Launch the interface
|
| 32 |
+
iface.launch()
|