Danielrahmai1991 commited on
Commit
eb70223
·
verified ·
1 Parent(s): f3a20a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -53,10 +53,12 @@ llm = HuggingFacePipeline.from_model_id(
53
  chat_model = ChatHuggingFace(llm=llm)
54
 
55
  # history of the messages
56
- messages = []
57
 
58
- def llm_run(prompt):
59
- global messages
 
 
 
60
  print(f"question is {prompt}")
61
  lang = single_detection(prompt, api_key='4ab77f25578d450f0902fb42c66d5e11')
62
  if lang == 'en':
@@ -73,7 +75,22 @@ def llm_run(prompt):
73
  # def greet(prompt, m_type):
74
  # return "hi"
75
 
76
- demo = gr.Interface(fn=llm_run, inputs=["text"], outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  demo.launch(debug=True, share=True)
78
 
79
 
 
53
  chat_model = ChatHuggingFace(llm=llm)
54
 
55
  # history of the messages
 
56
 
57
+ def clear_memory(messages):
58
+ messages.clear()
59
+ return "Memory cleaned."
60
+
61
+ def llm_run(prompt, messages):
62
  print(f"question is {prompt}")
63
  lang = single_detection(prompt, api_key='4ab77f25578d450f0902fb42c66d5e11')
64
  if lang == 'en':
 
75
  # def greet(prompt, m_type):
76
  # return "hi"
77
 
78
+ with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.orange, secondary_hue=gr.themes.colors.pink)) as demo:
79
+ stored_message = gr.State([])
80
+ with gr.Row():
81
+ with gr.Column(scale=2):
82
+ text1 = gr.Textbox(lines=7, label="Prompt", scale=2)
83
+ with gr.Row():
84
+ btn1 = gr.Button("Submit", scale=1)
85
+ btn2 = gr.Button("Clear", scale=1)
86
+ btn3 = gr.Button("Clean Memory", scale=2)
87
+ with gr.Column(scale=2):
88
+ out_text = gr.Text(lines=15, label="Output", scale=2)
89
+ btn1.click(fn=llm_run, inputs=[text1, stored_message], outputs=out_text)
90
+ btn2.click(lambda: [None, None], outputs=[text1, out_text])
91
+ btn3.click(fn=clear_memory, inputs=[stored_message], outputs=[out_text])
92
+
93
+ # demo = gr.Interface(fn=llm_run, inputs=["text"], outputs="text")
94
  demo.launch(debug=True, share=True)
95
 
96