Spaces:
Paused
Paused
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,50 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from huggingface_hub import login
|
| 4 |
-
from transformers import pipeline
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
model_name = "
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
interface.launch(ssr_mode=False)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from huggingface_hub import login
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import torch
|
| 6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 7 |
+
|
| 8 |
+
# Load the gated model
|
| 9 |
+
#model_name = "RickyDeSkywalker/TheoremLlama"
|
| 10 |
+
#model_name = "unsloth/Llama-3.2-1B-Instruct"
|
| 11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
+
model_name = "internlm/internlm2-math-plus-7b"
|
| 13 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 14 |
+
#login(HF_TOKEN)
|
| 15 |
+
|
| 16 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 17 |
+
# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
|
| 18 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, torch_dtype=torch.float16).eval().to(device)
|
| 19 |
+
model = model.eval()
|
| 20 |
+
|
| 21 |
+
#generator = pipeline('text-generation', model=model_name, trust_remote_code=True, token=HF_TOKEN)
|
| 22 |
+
|
| 23 |
+
# Function for generating Lean 4 code
|
| 24 |
+
@torch.inference_mode()
|
| 25 |
+
def generate_lean4_code(prompt):
|
| 26 |
+
#result = generator(prompt, max_length=1000, num_return_sequences=1)
|
| 27 |
+
#return result[0]['generated_text']
|
| 28 |
+
response, history = model.chat(tokenizer, prompt, history=[], meta_instruction="")
|
| 29 |
+
print(response, history)
|
| 30 |
+
return response
|
| 31 |
+
|
| 32 |
+
# Gradio Interface
|
| 33 |
+
title = "Lean 4 Code Generation with TheoremLlama"
|
| 34 |
+
description = "Enter a natural language prompt to generate Lean 4 code."
|
| 35 |
+
|
| 36 |
+
interface = gr.Interface(
|
| 37 |
+
fn=generate_lean4_code,
|
| 38 |
+
inputs=gr.Textbox(
|
| 39 |
+
label="Prompt",
|
| 40 |
+
placeholder="Prove that the sum of two even numbers is even.",
|
| 41 |
+
lines=4
|
| 42 |
+
),
|
| 43 |
+
#outputs=gr.Code(label="Generated Lean 4 Code", language="lean"),
|
| 44 |
+
outputs=gr.Code(label="Generated Lean 4 Code"),
|
| 45 |
+
title=title,
|
| 46 |
+
description=description
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Launch the Gradio app
|
| 50 |
interface.launch(ssr_mode=False)
|