OmAlve commited on
Commit
b45d4d9
·
verified ·
1 Parent(s): cc0c092

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pydantic import BaseModel, Field
3
+ from typing import List
4
+ from groq import Groq
5
+ import instructor
6
+ from dotenv import load_dotenv
7
+
8
+ import gradio as gr
9
+
10
+ load_dotenv()
11
+
12
+ client = Groq(
13
+ api_key=os.getenv("GROQ_API_KEY"),
14
+ )
15
+ class Output(BaseModel):
16
+ latex: str
17
+
18
+ client = instructor.from_groq(client, mode=instructor.Mode.TOOLS)
19
+
20
+
21
+ def get_LaTeX(query):
22
+ prompt = f"""
23
+ You are a tool which takes in natural language descriptions and give out LaTeX according to the instructions in the input
24
+ Output LaTeX for the following:
25
+ {query}
26
+ """
27
+ resp = client.chat.completions.create(
28
+ model="llama3-8b-8192",
29
+ messages=[
30
+ {
31
+ "role": "user",
32
+ "content": prompt,
33
+ }
34
+ ],
35
+ response_model=Output,
36
+ )
37
+ return resp.latex,"$$\\begin{align*}" + resp.latex + "\\end{align*}$$"
38
+
39
+ css = """
40
+ #submit-btn {
41
+ background: #8957E5;
42
+ }
43
+ """
44
+
45
+ with gr.Blocks(theme=gr.themes.Default(primary_hue="purple"),css=css) as demo:
46
+ gr.HTML("<h1><center>Text to LaTeX<center><h1>")
47
+ gr.HTML("<h3><center>Just type a query in natural language and get back LaTeX, you can verify it by looking at the rendered LaTeX!</center></h3>")
48
+ with gr.Row():
49
+ with gr.Column():
50
+ input = gr.Textbox(label="Input Text")
51
+ submit_btn = gr.Button(value='Submit',elem_id='submit-btn')
52
+ with gr.Column():
53
+ output = gr.Text(label='LaTeX',interactive=False)
54
+ rendered_latex = gr.Markdown(label="Rendered LaTeX")
55
+
56
+ gr.on(
57
+ triggers=[input.submit, submit_btn.click],
58
+ inputs=input,
59
+ fn=get_LaTeX,
60
+ outputs=[output,rendered_latex]
61
+ )
62
+ if __name__ == "__main__":
63
+ demo.launch()