likhonsheikh commited on
Commit
e631985
·
verified ·
1 Parent(s): ef14f65
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
+ import uuid
5
+ import requests
6
+
7
+ # Optional: Set Typst binary path
8
+ TYPST_PATH = "typst"
9
+
10
+ # Temporary working directory
11
+ WORKDIR = "/tmp/sheikh_promptor"
12
+
13
+ os.makedirs(WORKDIR, exist_ok=True)
14
+
15
+
16
+ def build_typst_preview(code: str) -> tuple:
17
+ file_id = str(uuid.uuid4())
18
+ typ_path = os.path.join(WORKDIR, f"{file_id}.typ")
19
+ pdf_path = os.path.join(WORKDIR, f"{file_id}.pdf")
20
+
21
+ with open(typ_path, "w") as f:
22
+ f.write(code)
23
+
24
+ try:
25
+ subprocess.run([TYPST_PATH, "compile", typ_path, "-o", pdf_path],
26
+ check=True, capture_output=True)
27
+ return (pdf_path, None)
28
+ except subprocess.CalledProcessError as e:
29
+ return (None, e.stderr.decode())
30
+
31
+
32
+ def ai_generate_response(prompt: str, model="together") -> str:
33
+ # Add your Together/Groq API call here
34
+ if model == "together":
35
+ # Replace with real API integration
36
+ return f"[TogetherAI] ➜ Generated content for: {prompt}"
37
+ else:
38
+ return f"[GroqAI] ➜ Placeholder for: {prompt}"
39
+
40
+
41
+ def run_prompt_and_compile(prompt, model, code):
42
+ ai_result = ai_generate_response(prompt, model)
43
+ final_code = f"{code}\n\n// AI Suggestion:\n// {ai_result}"
44
+ pdf, err = build_typst_preview(final_code)
45
+ return final_code, ai_result, (pdf if pdf else None), (err if err else "Build succeeded.")
46
+
47
+
48
+ # Gradio UI
49
+ with gr.Blocks(css="body { font-family: Inter, sans-serif; }") as demo:
50
+ gr.Markdown("# **SheikhPromptor.run**")
51
+
52
+ with gr.Row():
53
+ code_editor = gr.Code(label="Typst/LaTeX/Markdown", language="typst", lines=20)
54
+ prompt_input = gr.Textbox(label="AI Prompt", placeholder="e.g. Generate a table in Typst")
55
+ model_select = gr.Dropdown(["together", "groq"], label="AI Model", value="together")
56
+
57
+ with gr.Row():
58
+ run_button = gr.Button("Run Prompt + Compile")
59
+
60
+ with gr.Row():
61
+ ai_output = gr.Textbox(label="AI Response")
62
+
63
+ with gr.Row():
64
+ pdf_preview = gr.File(label="PDF Output", file_types=[".pdf"])
65
+ compiler_log = gr.Textbox(label="Compiler Log")
66
+
67
+ run_button.click(
68
+ fn=run_prompt_and_compile,
69
+ inputs=[prompt_input, model_select, code_editor],
70
+ outputs=[code_editor, ai_output, pdf_preview, compiler_log]
71
+ )
72
+
73
+ demo.launch()