Sávio Santos commited on
Commit
f897f8d
·
1 Parent(s): 779929a

fix layout

Browse files
Files changed (4) hide show
  1. app.py +10 -7
  2. requirements.txt +0 -1
  3. src/agent.py +3 -3
  4. src/interface.py +12 -2
app.py CHANGED
@@ -2,22 +2,25 @@ from src.agent import PlantUMLAgent
2
  from src.documents import get_processed_documents, get_diagrams_names
3
  from src.interface import create_interface
4
  from src.preview import render_plantuml, sanitize_plantuml_code
 
5
 
6
  from cachetools import LRUCache, cached
7
 
8
- from dotenv import load_dotenv
9
-
10
- load_dotenv()
11
-
12
  diagrams_names = get_diagrams_names()
13
  docs_processed = get_processed_documents(diagrams_names)
14
 
15
- agent = PlantUMLAgent('mistral-small-latest', docs_processed)
16
-
17
  cache = LRUCache(maxsize=100)
18
 
19
  @cached(cache)
20
- def respond(message, diagram_name):
 
 
 
 
 
 
 
 
21
  response = agent.predict(message, diagram_name)
22
 
23
  plantuml_code = sanitize_plantuml_code(response)
 
2
  from src.documents import get_processed_documents, get_diagrams_names
3
  from src.interface import create_interface
4
  from src.preview import render_plantuml, sanitize_plantuml_code
5
+ import gradio as gr
6
 
7
  from cachetools import LRUCache, cached
8
 
 
 
 
 
9
  diagrams_names = get_diagrams_names()
10
  docs_processed = get_processed_documents(diagrams_names)
11
 
 
 
12
  cache = LRUCache(maxsize=100)
13
 
14
  @cached(cache)
15
+ def respond(message, diagram_name, api_key):
16
+ if not api_key:
17
+ gr.Warning("Please provide a valid Mistral API key to generate diagrams.")
18
+ return message, "", ""
19
+ if not message:
20
+ gr.Warning("Please provide a description for the UML diagram.")
21
+ return "", "", ""
22
+
23
+ agent = PlantUMLAgent('mistral-small-latest', docs_processed, api_key)
24
  response = agent.predict(message, diagram_name)
25
 
26
  plantuml_code = sanitize_plantuml_code(response)
requirements.txt CHANGED
@@ -3,7 +3,6 @@ langchain
3
  langchain_community
4
  rank_bm25
5
  numpy==1.26.4
6
- python-dotenv
7
  cachetools
8
  beautifulsoup4
9
  docling
 
3
  langchain_community
4
  rank_bm25
5
  numpy==1.26.4
 
6
  cachetools
7
  beautifulsoup4
8
  docling
src/agent.py CHANGED
@@ -1,12 +1,12 @@
1
  from langchain_community.retrievers import BM25Retriever
2
  from mistralai import Mistral
3
- import os
4
 
5
  class PlantUMLAgent:
6
- def __init__(self, model, docs_processed):
7
  self.model = model
8
  self.docs_processed = docs_processed
9
- self.client = Mistral(api_key=os.getenv("MISTRAL_API_KEY"))
 
10
 
11
  def predict(self, message, diagram_name):
12
  diagram_name = diagram_name.replace(" ", "-").lower()
 
1
  from langchain_community.retrievers import BM25Retriever
2
  from mistralai import Mistral
 
3
 
4
  class PlantUMLAgent:
5
+ def __init__(self, model, docs_processed, api_key):
6
  self.model = model
7
  self.docs_processed = docs_processed
8
+ self.client = Mistral(api_key=api_key)
9
+
10
 
11
  def predict(self, message, diagram_name):
12
  diagram_name = diagram_name.replace(" ", "-").lower()
src/interface.py CHANGED
@@ -26,6 +26,16 @@ def create_interface(diagram_types, respond):
26
 
27
  with gr.Row():
28
  with gr.Column(scale=1):
 
 
 
 
 
 
 
 
 
 
29
  gr.Markdown("## 📝 Input Description")
30
  msg = gr.Textbox(
31
  label="Describe your UML diagram",
@@ -73,7 +83,7 @@ def create_interface(diagram_types, respond):
73
  """
74
  )
75
 
76
- submit.click(respond, [msg, diagram_dropdown], [msg, diagram_text_output, diagram_output])
77
- msg.submit(respond, [msg, diagram_dropdown], [msg, diagram_text_output, diagram_output])
78
 
79
  return demo
 
26
 
27
  with gr.Row():
28
  with gr.Column(scale=1):
29
+
30
+ gr.Markdown("## 🔑 Mistral API Key Input")
31
+ api_key_input = gr.Textbox(
32
+ label="🔐 Mistral API Key",
33
+ placeholder="Input your Mistral API key here",
34
+ type="password",
35
+ lines=1,
36
+ interactive=True
37
+ )
38
+
39
  gr.Markdown("## 📝 Input Description")
40
  msg = gr.Textbox(
41
  label="Describe your UML diagram",
 
83
  """
84
  )
85
 
86
+ submit.click(respond, [msg, diagram_dropdown, api_key_input], [msg, diagram_text_output, diagram_output])
87
+ msg.submit(respond, [msg, diagram_dropdown, api_key_input], [msg, diagram_text_output, diagram_output])
88
 
89
  return demo