prithivMLmods commited on
Commit
081f185
·
verified ·
1 Parent(s): f76444e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -32
app.py CHANGED
@@ -198,7 +198,7 @@ SYSTEM_PROMPT = """
198
  "2. **Code**: Write Python code to implement your solution.\n"
199
  "3. **Observation**: Analyze the output of the code and summarize the results.\n"
200
  "4. **Final Answer**: Provide a concise conclusion or final result.\n\n"
201
- f"Task: {task}"
202
 
203
  """
204
 
@@ -231,7 +231,15 @@ def ragent_reasoning(prompt: str, history: list[dict], max_tokens: int = 1024, t
231
  # Gradio UI configuration
232
 
233
  DESCRIPTION = """
234
- # Agent Dino 🌠 """
 
 
 
 
 
 
 
 
235
 
236
  css = '''
237
  h1 {
@@ -239,6 +247,7 @@ h1 {
239
  display: block;
240
  }
241
 
 
242
  #duplicate-button {
243
  margin: auto;
244
  color: #fff;
@@ -568,42 +577,99 @@ def generate(
568
  output_file = asyncio.run(text_to_speech(final_response, voice))
569
  yield gr.Audio(output_file, autoplay=True)
570
 
571
- # Gradio Chat Interface Setup and Launch
572
-
573
- demo = gr.ChatInterface(
574
- fn=generate,
575
- additional_inputs=[
576
- gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS),
577
- gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, step=0.1, value=0.6),
578
- gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9),
579
- gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50),
580
- gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2),
581
- ],
582
- examples=[
583
- ["@tts2 What causes rainbows to form?"],
584
- ["@3d A birthday cupcake with cherry"],
585
- [{"text": "summarize the letter", "files": ["examples/1.png"]}],
586
- ["@image Chocolate dripping from a donut against a yellow background, in the style of brocore, hyper-realistic"],
587
- ["@rAgent Explain how a binary search algorithm works."],
588
- ["@web latest breakthroughs in renewable energy"],
589
-
590
- ],
591
- cache_examples=False,
592
- type="messages",
593
- description=DESCRIPTION,
594
- css=css,
595
- fill_height=True,
596
- textbox=gr.MultimodalTextbox(label="Query Input", file_types=["image"], file_count="multiple"),
597
- stop_btn="Stop Generation",
598
- multimodal=True,
599
- )
600
 
601
  # Ensure the static folder exists
602
  if not os.path.exists("static"):
603
  os.makedirs("static")
604
 
605
  from fastapi.staticfiles import StaticFiles
606
- demo.app.mount("/static", StaticFiles(directory="static"), name="static")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
 
608
  if __name__ == "__main__":
609
  demo.queue(max_size=20).launch(share=True)
 
198
  "2. **Code**: Write Python code to implement your solution.\n"
199
  "3. **Observation**: Analyze the output of the code and summarize the results.\n"
200
  "4. **Final Answer**: Provide a concise conclusion or final result.\n\n"
201
+ f"Task: {{task}}"
202
 
203
  """
204
 
 
231
  # Gradio UI configuration
232
 
233
  DESCRIPTION = """
234
+ # Agent Dino 🌠
235
+
236
+ This chat interface supports multiple commands:
237
+ - `@tts1` or `@tts2`: Triggers text-to-speech.
238
+ - `@image`: Generates an image using Stable Diffusion XL.
239
+ - `@3d`: Generates a 3D model using the ShapE pipeline.
240
+ - `@web`: Performs a web search or visits a webpage.
241
+ - `@rAgent`: Initiates a reasoning chain using Llama mode OpenAI.
242
+ """
243
 
244
  css = '''
245
  h1 {
 
247
  display: block;
248
  }
249
 
250
+ /* Additional styling can go here */
251
  #duplicate-button {
252
  margin: auto;
253
  color: #fff;
 
577
  output_file = asyncio.run(text_to_speech(final_response, voice))
578
  yield gr.Audio(output_file, autoplay=True)
579
 
580
+ # ---------------------------
581
+ # Gradio Interface Setup
582
+ # ---------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
 
584
  # Ensure the static folder exists
585
  if not os.path.exists("static"):
586
  os.makedirs("static")
587
 
588
  from fastapi.staticfiles import StaticFiles
589
+
590
+ # Wrap the app in a Blocks layout to include an extra slider bar (via HTML/CSS)
591
+ with gr.Blocks(css=css) as demo:
592
+ gr.Markdown("### About Space\nThis chat interface supports multiple commands:\n- `@tts1` or `@tts2`: Triggers text-to-speech.\n- `@image`: Generates an image using Stable Diffusion XL.\n- `@3d`: Generates a 3D model using the ShapE pipeline.\n- `@web`: Performs a web search or visits a webpage.\n- `@rAgent`: Initiates a reasoning chain using Llama mode OpenAI.\n")
593
+
594
+ # Add a custom slider bar via HTML/CSS/JS
595
+ gr.HTML("""
596
+ <div class="slider-container">
597
+ <input type="range" min="1" max="100" value="50" class="slider" id="myRange">
598
+ <p>Slider Value: <span id="sliderValue">50</span></p>
599
+ </div>
600
+ <style>
601
+ .slider-container {
602
+ width: 80%;
603
+ margin: auto;
604
+ text-align: center;
605
+ padding: 10px 0;
606
+ }
607
+ .slider {
608
+ -webkit-appearance: none;
609
+ width: 100%;
610
+ height: 15px;
611
+ background: #d3d3d3;
612
+ outline: none;
613
+ opacity: 0.7;
614
+ transition: opacity .2s;
615
+ }
616
+ .slider:hover {
617
+ opacity: 1;
618
+ }
619
+ .slider::-webkit-slider-thumb {
620
+ -webkit-appearance: none;
621
+ appearance: none;
622
+ width: 25px;
623
+ height: 25px;
624
+ background: #4CAF50;
625
+ cursor: pointer;
626
+ }
627
+ .slider::-moz-range-thumb {
628
+ width: 25px;
629
+ height: 25px;
630
+ background: #4CAF50;
631
+ cursor: pointer;
632
+ }
633
+ </style>
634
+ <script>
635
+ const slider = document.getElementById("myRange");
636
+ const sliderValue = document.getElementById("sliderValue");
637
+ slider.oninput = function() {
638
+ sliderValue.textContent = this.value;
639
+ }
640
+ </script>
641
+ """)
642
+
643
+ # Add the ChatInterface (with additional slider controls for generation parameters)
644
+ gr.ChatInterface(
645
+ fn=generate,
646
+ additional_inputs=[
647
+ gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS),
648
+ gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, step=0.1, value=0.6),
649
+ gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9),
650
+ gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50),
651
+ gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2),
652
+ ],
653
+ examples=[
654
+ ["@tts2 What causes rainbows to form?"],
655
+ ["@3d A birthday cupcake with cherry"],
656
+ [{"text": "summarize the letter", "files": ["examples/1.png"]}],
657
+ ["@image Chocolate dripping from a donut against a yellow background, in the style of brocore, hyper-realistic"],
658
+ ["@rAgent Explain how a binary search algorithm works."],
659
+ ["@web latest breakthroughs in renewable energy"],
660
+ ],
661
+ cache_examples=False,
662
+ type="messages",
663
+ description=DESCRIPTION,
664
+ css=css,
665
+ fill_height=True,
666
+ textbox=gr.MultimodalTextbox(label="Query Input", file_types=["image"], file_count="multiple"),
667
+ stop_btn="Stop Generation",
668
+ multimodal=True,
669
+ )
670
+
671
+ # Mount the static folder so generated files can be served
672
+ demo.app.mount("/static", StaticFiles(directory="static"), name="static")
673
 
674
  if __name__ == "__main__":
675
  demo.queue(max_size=20).launch(share=True)