Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,99 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
self.output_path = output_path
|
| 5 |
-
|
| 6 |
-
def generate_code(self, user_input: dict) -> str:
|
| 7 |
-
# Generate the code based on the user_input and the app template
|
| 8 |
-
tokenizer, model = load_model(user_input["model_name"], user_input["model_path"])
|
| 9 |
-
# Use the tokenizer and model to generate the code
|
| 10 |
-
pass
|
| 11 |
-
|
| 12 |
-
def load_model(self, model_name: str, model_path: str) -> Any:
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 14 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
|
| 15 |
-
return tokenizer, model
|
| 16 |
-
|
| 17 |
-
def main(self, port: int = 8000, debug: bool = False) -> None:
|
| 18 |
-
# Implement the main function that creates the Gradio interface and launches the app
|
| 19 |
-
pass
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
# Generate the code
|
| 29 |
-
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
import huggingface_hub
|
| 6 |
+
|
| 7 |
+
from huggingface_hub.commands import HfFolder
|
| 8 |
+
|
| 9 |
+
import transformers
|
| 10 |
+
|
| 11 |
+
from transformers import pipeline
|
| 12 |
+
|
| 13 |
+
import gradio as gr
|
| 14 |
+
|
| 15 |
+
import tempfile
|
| 16 |
+
|
| 17 |
+
from huggingface_hub import HfFolder
|
| 18 |
|
| 19 |
+
def main():
|
| 20 |
+
# Get the user's idea
|
| 21 |
+
idea = input("What is your idea for an application? ")
|
| 22 |
|
| 23 |
+
# Generate the code for the application
|
| 24 |
+
code = gemmacode.generate(idea)
|
| 25 |
|
| 26 |
+
# Test the code
|
| 27 |
+
try:
|
| 28 |
+
transformers.pipeline("text-generation")(code)
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print("The code failed to run:", e)
|
| 31 |
+
return
|
| 32 |
|
| 33 |
+
# Ensure the functionality of the application
|
| 34 |
+
try:
|
| 35 |
+
gr.Interface(fn=transformers.pipeline("text-generation"), inputs=gr.Textbox(), outputs=gr.Textbox()).launch()
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print("The application failed to run:", e)
|
| 38 |
+
return
|
| 39 |
+
|
| 40 |
+
# Provide an embedded webapp demo of the user's idea implementation
|
| 41 |
+
try:
|
| 42 |
+
hf_folder = HfFolder(path=tempfile.mkdtemp())
|
| 43 |
+
hf_folder.save(code)
|
| 44 |
+
hf_folder.push_to_hub(repo_id="acecalisto3/gemmacode-demo", commit_message="Initial commit")
|
| 45 |
+
print(f"The demo is available at: https://huggingface.co/acecalisto3/gemmacode-demo")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print("The demo failed to launch:", e)
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
# Offer the option to rebuild or deploy
|
| 51 |
+
while True:
|
| 52 |
+
choice = input("Do you want to rebuild or deploy the application? (r/d/q) ")
|
| 53 |
+
if choice == "r":
|
| 54 |
+
# Rebuild the code
|
| 55 |
+
code = gemmacode.generate(idea)
|
| 56 |
+
|
| 57 |
+
# Test the code
|
| 58 |
+
try:
|
| 59 |
+
transformers.pipeline("text-generation")(code)
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print("The code failed to run:", e)
|
| 62 |
+
return
|
| 63 |
+
|
| 64 |
+
# Ensure the functionality of the application
|
| 65 |
+
try:
|
| 66 |
+
gr.Interface(fn=transformers.pipeline("text-generation"), inputs=gr.Textbox(), outputs=gr.Textbox()).launch()
|
| 67 |
+
except Exception as e:
|
| 68 |
+
print("The application failed to run:", e)
|
| 69 |
+
return
|
| 70 |
+
|
| 71 |
+
# Provide an embedded webapp demo of the user's idea implementation
|
| 72 |
+
try:
|
| 73 |
+
hf_folder = HfFolder(path=tempfile.mkdtemp())
|
| 74 |
+
hf_folder.save(code)
|
| 75 |
+
hf_folder.push_to_hub(repo_id="acecalisto3/gemmacode-demo", commit_message="Initial commit")
|
| 76 |
+
print(f"The demo is available at: https://huggingface.co/acecalisto3/gemmacode-demo")
|
| 77 |
+
except Exception as e:
|
| 78 |
+
print("The demo failed to launch:", e)
|
| 79 |
+
return
|
| 80 |
+
elif choice == "d":
|
| 81 |
+
# Deploy the application
|
| 82 |
+
try:
|
| 83 |
+
api_token = os.environ["HF_TOKEN"]
|
| 84 |
+
hub = huggingface_hub.HfApi(api_token=api_token)
|
| 85 |
+
hub.create_repo(name="my-app", organization="my-org")
|
| 86 |
+
hf_folder = HfFolder(path=tempfile.mkdtemp())
|
| 87 |
+
hf_folder.save(code)
|
| 88 |
+
hf_folder.push_to_hub(repo_id="my-org/my-app", commit_message="Initial commit")
|
| 89 |
+
print("The application has been deployed to: https://huggingface.co/my-org/my-app")
|
| 90 |
+
except Exception as e:
|
| 91 |
+
print("The application failed to deploy:", e)
|
| 92 |
+
return
|
| 93 |
+
elif choice == "q":
|
| 94 |
+
break
|
| 95 |
+
else:
|
| 96 |
+
print("Invalid choice")
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
main()
|