File size: 39,460 Bytes
88f3fce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 |
"""
Hugging Face Models Interface for OpenManus Gradio App
Advanced UI for accessing and using HuggingFace models
"""
import base64
import io
from typing import Dict, Tuple
import gradio as gr
import PIL.Image
from app.agent.huggingface_agent import HuggingFaceAgent
from app.huggingface_models import HuggingFaceModels, ModelCategory
class HuggingFaceModelsInterface:
"""Gradio interface for HuggingFace models integration"""
def __init__(self, hf_agent: HuggingFaceAgent):
self.hf_agent = hf_agent
self.models = HuggingFaceModels()
def create_interface(self) -> gr.Interface:
"""Create the HuggingFace models Gradio interface"""
with gr.Blocks(title="๐ค HuggingFace Models") as interface:
gr.Markdown("# ๐ค HuggingFace Models Integration")
gr.Markdown(
"Access thousands of state-of-the-art AI models via HuggingFace Inference API"
)
with gr.Tabs():
# Core AI Tabs
with gr.TabItem("๐ Text Generation"):
self._create_text_generation_interface()
with gr.TabItem("๐จ Image Generation"):
self._create_image_generation_interface()
with gr.TabItem("๐ต Audio Processing"):
self._create_audio_processing_interface()
with gr.TabItem("๐๏ธ Image Analysis"):
self._create_image_analysis_interface()
with gr.TabItem("๐ Text Analysis"):
self._create_text_analysis_interface()
# New Advanced Tabs
with gr.TabItem("๐ฌ Video Generation"):
self._create_video_generation_interface()
with gr.TabItem("๐ป Code Generation"):
self._create_code_generation_interface()
with gr.TabItem("๐ง 3D Creation"):
self._create_3d_generation_interface()
with gr.TabItem("๐ Document Processing"):
self._create_document_processing_interface()
with gr.TabItem("๐ Multimodal AI"):
self._create_multimodal_interface()
with gr.TabItem("๐ญ Creative Content"):
self._create_creative_content_interface()
with gr.TabItem("๐ฎ Game Development"):
self._create_game_development_interface()
with gr.TabItem("๏ฟฝ Science & Research"):
self._create_science_research_interface()
with gr.TabItem("๐ผ Business Tools"):
self._create_business_tools_interface()
with gr.TabItem("๐๏ธ Model Browser"):
self._create_model_browser_interface()
return interface
def _create_text_generation_interface(self):
"""Create text generation interface"""
gr.Markdown("## Generate text with powerful language models")
with gr.Row():
with gr.Column():
text_model_dropdown = gr.Dropdown(
choices=[
model.name for model in self.models.TEXT_GENERATION_MODELS
],
value="MiniMax-M2",
label="Text Generation Model",
info="Choose from the latest and most powerful language models",
)
text_prompt = gr.Textbox(
label="Prompt",
placeholder="Enter your text prompt here...",
lines=4,
max_lines=10,
)
with gr.Row():
text_max_tokens = gr.Slider(
minimum=10, maximum=2048, value=200, step=10, label="Max Tokens"
)
text_temperature = gr.Slider(
minimum=0.0,
maximum=2.0,
value=0.7,
step=0.1,
label="Temperature",
)
text_generate_btn = gr.Button("๐ Generate Text", variant="primary")
with gr.Column():
text_output = gr.Textbox(
label="Generated Text", lines=10, max_lines=20, interactive=False
)
text_info = gr.JSON(label="Model Info", visible=False)
text_generate_btn.click(
fn=self._generate_text,
inputs=[
text_model_dropdown,
text_prompt,
text_max_tokens,
text_temperature,
],
outputs=[text_output, text_info],
)
def _create_image_generation_interface(self):
"""Create image generation interface"""
gr.Markdown("## Create stunning images from text descriptions")
with gr.Row():
with gr.Column():
image_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.TEXT_TO_IMAGE_MODELS],
value="FLUX.1 Dev",
label="Image Generation Model",
info="State-of-the-art text-to-image models",
)
image_prompt = gr.Textbox(
label="Image Prompt",
placeholder="Describe the image you want to create...",
lines=3,
)
image_negative_prompt = gr.Textbox(
label="Negative Prompt (Optional)",
placeholder="What to avoid in the image...",
lines=2,
)
with gr.Row():
image_width = gr.Slider(
minimum=256, maximum=2048, value=1024, step=64, label="Width"
)
image_height = gr.Slider(
minimum=256, maximum=2048, value=1024, step=64, label="Height"
)
image_generate_btn = gr.Button("๐จ Generate Image", variant="primary")
with gr.Column():
image_output = gr.Image(label="Generated Image", type="pil")
image_info = gr.JSON(label="Generation Info", visible=False)
image_generate_btn.click(
fn=self._generate_image,
inputs=[
image_model_dropdown,
image_prompt,
image_negative_prompt,
image_width,
image_height,
],
outputs=[image_output, image_info],
)
def _create_audio_processing_interface(self):
"""Create audio processing interface"""
gr.Markdown("## Speech recognition and text-to-speech")
with gr.Tabs():
with gr.TabItem("๐ค Speech Recognition"):
with gr.Row():
with gr.Column():
asr_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.ASR_MODELS],
value="Whisper Large v3",
label="Speech Recognition Model",
)
audio_input = gr.Audio(
label="Upload Audio File", type="filepath"
)
asr_language = gr.Dropdown(
choices=[
"auto",
"en",
"es",
"fr",
"de",
"it",
"pt",
"ru",
"ja",
"ko",
"zh",
],
value="auto",
label="Language (auto-detect if not specified)",
)
transcribe_btn = gr.Button("๐ Transcribe", variant="primary")
with gr.Column():
transcription_output = gr.Textbox(
label="Transcription", lines=8, interactive=False
)
with gr.TabItem("๐ Text-to-Speech"):
with gr.Row():
with gr.Column():
tts_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.TTS_MODELS],
value="Kokoro 82M",
label="Text-to-Speech Model",
)
tts_text = gr.Textbox(
label="Text to Speak",
placeholder="Enter text to convert to speech...",
lines=4,
)
tts_voice = gr.Textbox(
label="Voice ID (Optional)",
placeholder="Leave empty for default voice",
)
synthesize_btn = gr.Button("๐ Synthesize", variant="primary")
with gr.Column():
audio_output = gr.Audio(label="Generated Audio")
transcribe_btn.click(
fn=self._transcribe_audio,
inputs=[asr_model_dropdown, audio_input, asr_language],
outputs=[transcription_output],
)
synthesize_btn.click(
fn=self._synthesize_speech,
inputs=[tts_model_dropdown, tts_text, tts_voice],
outputs=[audio_output],
)
def _create_image_analysis_interface(self):
"""Create image analysis interface"""
gr.Markdown("## Analyze and classify images")
with gr.Row():
with gr.Column():
analysis_model_dropdown = gr.Dropdown(
choices=[
model.name for model in self.models.IMAGE_CLASSIFICATION_MODELS
],
value="ViT Base Patch16",
label="Image Analysis Model",
)
analysis_task = gr.Radio(
choices=[
"General Classification",
"NSFW Detection",
"Emotion Recognition",
"Deepfake Detection",
],
value="General Classification",
label="Analysis Task",
)
image_input = gr.Image(label="Upload Image", type="pil")
analyze_btn = gr.Button("๐ Analyze Image", variant="primary")
with gr.Column():
analysis_output = gr.JSON(label="Analysis Results")
analysis_confidence = gr.Plot(label="Confidence Scores")
analyze_btn.click(
fn=self._analyze_image,
inputs=[analysis_model_dropdown, analysis_task, image_input],
outputs=[analysis_output, analysis_confidence],
)
def _create_text_analysis_interface(self):
"""Create text analysis interface"""
gr.Markdown("## Analyze, translate, and summarize text")
with gr.Tabs():
with gr.TabItem("๐ Translation"):
with gr.Row():
with gr.Column():
translation_text = gr.Textbox(
label="Text to Translate", lines=5
)
with gr.Row():
source_lang = gr.Dropdown(
choices=[
"auto",
"en",
"es",
"fr",
"de",
"it",
"pt",
"ru",
"ja",
"ko",
"zh",
],
value="auto",
label="Source Language",
)
target_lang = gr.Dropdown(
choices=[
"en",
"es",
"fr",
"de",
"it",
"pt",
"ru",
"ja",
"ko",
"zh",
],
value="en",
label="Target Language",
)
translate_btn = gr.Button("๐ Translate", variant="primary")
with gr.Column():
translation_output = gr.Textbox(
label="Translation", lines=5, interactive=False
)
with gr.TabItem("๐ Summarization"):
with gr.Row():
with gr.Column():
summary_text = gr.Textbox(
label="Text to Summarize",
lines=8,
placeholder="Paste long text here...",
)
summary_length = gr.Slider(
minimum=50,
maximum=500,
value=150,
step=25,
label="Summary Length",
)
summarize_btn = gr.Button("๐ Summarize", variant="primary")
with gr.Column():
summary_output = gr.Textbox(
label="Summary", lines=8, interactive=False
)
translate_btn.click(
fn=self._translate_text,
inputs=[translation_text, source_lang, target_lang],
outputs=[translation_output],
)
summarize_btn.click(
fn=self._summarize_text,
inputs=[summary_text, summary_length],
outputs=[summary_output],
)
def _create_model_browser_interface(self):
"""Create model browser interface"""
gr.Markdown("## Browse available HuggingFace models")
category_dropdown = gr.Dropdown(
choices=[cat.value for cat in ModelCategory],
value="text-generation",
label="Model Category",
)
refresh_btn = gr.Button("๐ Refresh Models")
models_display = gr.DataFrame(
headers=["Model Name", "Model ID", "Description", "Compatible"],
label="Available Models",
interactive=False,
)
def update_models(category):
models_data = []
if category:
models = self.hf_agent.get_available_hf_models(category)
if "models" in models:
for model in models["models"]:
models_data.append(
[
model["name"],
model["model_id"],
(
model["description"][:100] + "..."
if len(model["description"]) > 100
else model["description"]
),
"โ
" if model["endpoint_compatible"] else "โ",
]
)
return models_data
category_dropdown.change(
fn=update_models, inputs=[category_dropdown], outputs=[models_display]
)
refresh_btn.click(
fn=update_models, inputs=[category_dropdown], outputs=[models_display]
)
async def _generate_text(
self, model_name: str, prompt: str, max_tokens: int, temperature: float
) -> Tuple[str, Dict]:
"""Generate text using selected model"""
try:
result = await self.hf_agent.generate_text_with_hf(
prompt=prompt,
model_name=model_name,
max_tokens=max_tokens,
temperature=temperature,
)
if "error" in result:
return f"Error: {result['error']}", {}
# Extract text from result
generated_text = ""
if "result" in result and isinstance(result["result"], list):
generated_text = result["result"][0].get("generated_text", "")
elif "result" in result and isinstance(result["result"], dict):
generated_text = result["result"].get("generated_text", "")
return generated_text, result
except Exception as e:
return f"Error: {str(e)}", {}
async def _generate_image(
self,
model_name: str,
prompt: str,
negative_prompt: str,
width: int,
height: int,
) -> Tuple[PIL.Image.Image, Dict]:
"""Generate image using selected model"""
try:
result = await self.hf_agent.generate_image_with_hf(
prompt=prompt,
model_name=model_name,
negative_prompt=negative_prompt or None,
width=width,
height=height,
)
if "error" in result:
return None, result
# Convert base64 to PIL Image
if "image_base64" in result:
image_data = base64.b64decode(result["image_base64"])
image = PIL.Image.open(io.BytesIO(image_data))
return image, result
return None, result
except Exception as e:
return None, {"error": str(e)}
async def _transcribe_audio(
self, model_name: str, audio_path: str, language: str
) -> str:
"""Transcribe audio using selected model"""
try:
if not audio_path:
return "Please upload an audio file"
with open(audio_path, "rb") as f:
audio_data = f.read()
result = await self.hf_agent.transcribe_audio_with_hf(
audio_data=audio_data,
model_name=model_name,
language=language if language != "auto" else None,
)
if "error" in result:
return f"Error: {result['error']}"
return result.get("transcription", "No transcription available")
except Exception as e:
return f"Error: {str(e)}"
async def _synthesize_speech(
self, model_name: str, text: str, voice_id: str
) -> bytes:
"""Synthesize speech using selected model"""
try:
if not text.strip():
return None
result = await self.hf_agent.synthesize_speech_with_hf(
text=text, model_name=model_name, voice_id=voice_id or None
)
if "error" in result:
return None
if "audio_base64" in result:
return base64.b64decode(result["audio_base64"])
return None
except Exception as e:
return None
async def _analyze_image(
self, model_name: str, task: str, image: PIL.Image.Image
) -> Tuple[Dict, gr.Plot]:
"""Analyze image using selected model"""
try:
if image is None:
return {"error": "Please upload an image"}, None
# Convert PIL to bytes
img_byte_arr = io.BytesIO()
image.save(img_byte_arr, format="PNG")
img_byte_arr = img_byte_arr.getvalue()
# Map task to model
task_models = {
"NSFW Detection": "NSFW Image Detection",
"Emotion Recognition": "Facial Emotions Detection",
"Deepfake Detection": "Deepfake Detection",
"General Classification": model_name,
}
selected_model = task_models.get(task, model_name)
result = await self.hf_agent.classify_image_with_hf(
image_data=img_byte_arr, model_name=selected_model
)
if "error" in result:
return result, None
return result, None
except Exception as e:
return {"error": str(e)}, None
async def _translate_text(
self, text: str, source_lang: str, target_lang: str
) -> str:
"""Translate text"""
try:
if not text.strip():
return "Please enter text to translate"
result = await self.hf_agent.translate_with_hf(
text=text,
source_language=source_lang if source_lang != "auto" else None,
target_language=target_lang,
)
if "error" in result:
return f"Error: {result['error']}"
return result.get("translation", {}).get(
"translation_text", "Translation failed"
)
except Exception as e:
return f"Error: {str(e)}"
async def _summarize_text(self, text: str, max_length: int) -> str:
"""Summarize text"""
try:
if not text.strip():
return "Please enter text to summarize"
result = await self.hf_agent.summarize_with_hf(
text=text, max_length=max_length
)
if "error" in result:
return f"Error: {result['error']}"
return result.get("summary", {}).get("summary_text", "Summarization failed")
except Exception:
return "Error: Summarization failed"
def _create_video_generation_interface(self):
"""Create video generation interface"""
gr.Markdown("## ๐ฌ Create videos from text descriptions")
with gr.Row():
with gr.Column():
video_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.VIDEO_GENERATION_MODELS],
value="Stable Video Diffusion",
label="Video Generation Model"
)
video_prompt = gr.Textbox(
label="Video Description",
placeholder="Describe the video you want to create...",
lines=3
)
with gr.Row():
video_duration = gr.Slider(
minimum=1,
maximum=30,
value=5,
step=1,
label="Duration (seconds)"
)
video_fps = gr.Slider(
minimum=12,
maximum=60,
value=24,
step=1,
label="FPS"
)
generate_video_btn = gr.Button("๐ฌ Generate Video", variant="primary")
with gr.Column():
video_output = gr.Video(label="Generated Video")
video_info = gr.JSON(label="Generation Info", visible=False)
def _create_code_generation_interface(self):
"""Create code generation interface"""
gr.Markdown("## ๐ป Generate code from natural language")
with gr.Tabs():
with gr.TabItem("Code Generation"):
with gr.Row():
with gr.Column():
code_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.CODE_GENERATION_MODELS],
value="CodeLlama 34B Instruct",
label="Code Generation Model"
)
code_prompt = gr.Textbox(
label="Code Description",
placeholder="Describe the code you want to generate...",
lines=4
)
code_language = gr.Dropdown(
choices=["python", "javascript", "java", "cpp", "c", "rust", "go", "swift"],
value="python",
label="Programming Language"
)
generate_code_btn = gr.Button("๐ป Generate Code", variant="primary")
with gr.Column():
code_output = gr.Code(label="Generated Code", language="python")
with gr.TabItem("App Generation"):
with gr.Row():
with gr.Column():
app_description = gr.Textbox(
label="App Description",
placeholder="Describe the application you want to create...",
lines=5
)
app_type = gr.Dropdown(
choices=["web_app", "mobile_app", "desktop_app", "api", "cli_tool"],
value="web_app",
label="Application Type"
)
generate_app_btn = gr.Button("๐ Generate App", variant="primary")
with gr.Column():
app_output = gr.Code(label="Generated App Code", language="python")
def _create_3d_generation_interface(self):
"""Create 3D model generation interface"""
gr.Markdown("## ๐ง Create 3D models and assets")
with gr.Tabs():
with gr.TabItem("Text to 3D"):
with gr.Row():
with gr.Column():
three_d_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.THREE_D_MODELS],
value="Shap-E",
label="3D Generation Model"
)
three_d_prompt = gr.Textbox(
label="3D Object Description",
placeholder="Describe the 3D object you want to create...",
lines=3
)
three_d_resolution = gr.Slider(
minimum=32,
maximum=256,
value=64,
step=32,
label="Resolution"
)
generate_3d_btn = gr.Button("๐ง Generate 3D Model", variant="primary")
with gr.Column():
three_d_output = gr.File(label="Generated 3D Model")
with gr.TabItem("Image to 3D"):
with gr.Row():
with gr.Column():
image_3d_input = gr.Image(label="Input Image", type="pil")
convert_3d_btn = gr.Button("๐ Convert to 3D", variant="primary")
with gr.Column():
image_3d_output = gr.File(label="3D Model from Image")
def _create_document_processing_interface(self):
"""Create document processing interface"""
gr.Markdown("## ๐ Process and analyze documents")
with gr.Tabs():
with gr.TabItem("OCR"):
with gr.Row():
with gr.Column():
ocr_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.DOCUMENT_PROCESSING_MODELS if "ocr" in model.name.lower()],
value="TrOCR Large",
label="OCR Model"
)
ocr_image_input = gr.Image(label="Document Image", type="pil")
ocr_language = gr.Dropdown(
choices=["auto", "en", "es", "fr", "de", "it", "pt", "ru", "ja", "ko", "zh"],
value="auto",
label="Language"
)
extract_text_btn = gr.Button("๐ Extract Text", variant="primary")
with gr.Column():
ocr_output = gr.Textbox(label="Extracted Text", lines=10)
with gr.TabItem("Document Analysis"):
with gr.Row():
with gr.Column():
doc_file_input = gr.File(label="Upload Document", file_types=[".pdf", ".png", ".jpg", ".jpeg"])
analyze_doc_btn = gr.Button("๐ Analyze Document", variant="primary")
with gr.Column():
doc_analysis_output = gr.JSON(label="Document Analysis")
def _create_multimodal_interface(self):
"""Create multimodal AI interface"""
gr.Markdown("## ๐ Combine vision, text, and reasoning")
with gr.Row():
with gr.Column():
multimodal_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.MULTIMODAL_MODELS],
value="BLIP-2",
label="Multimodal Model"
)
multimodal_image = gr.Image(label="Input Image", type="pil")
multimodal_text = gr.Textbox(
label="Text Query/Instruction",
placeholder="Ask questions about the image or give instructions...",
lines=3
)
multimodal_task = gr.Radio(
choices=["Visual Q&A", "Image Captioning", "Multimodal Chat", "Cross-modal Generation"],
value="Visual Q&A",
label="Task Type"
)
process_multimodal_btn = gr.Button("๐ Process", variant="primary")
with gr.Column():
multimodal_output = gr.Textbox(label="Response", lines=8)
def _create_creative_content_interface(self):
"""Create creative content generation interface"""
gr.Markdown("## ๐ญ Generate creative content")
with gr.Tabs():
with gr.TabItem("Creative Writing"):
with gr.Row():
with gr.Column():
creative_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.CREATIVE_CONTENT_MODELS],
value="GPT-3.5 Creative",
label="Creative Writing Model"
)
creative_prompt = gr.Textbox(
label="Creative Prompt",
placeholder="Provide a creative writing prompt...",
lines=4
)
creative_type = gr.Dropdown(
choices=["story", "poem", "article", "script", "blog"],
value="story",
label="Content Type"
)
creative_length = gr.Slider(
minimum=100,
maximum=2000,
value=500,
step=100,
label="Length (words)"
)
generate_creative_btn = gr.Button("๐ญ Generate Content", variant="primary")
with gr.Column():
creative_output = gr.Textbox(label="Generated Content", lines=15)
def _create_game_development_interface(self):
"""Create game development interface"""
gr.Markdown("## ๐ฎ Generate game content and assets")
with gr.Tabs():
with gr.TabItem("Character Generation"):
with gr.Row():
with gr.Column():
character_prompt = gr.Textbox(
label="Character Description",
placeholder="Describe your game character...",
lines=4
)
character_type = gr.Dropdown(
choices=["hero", "villain", "npc", "companion", "boss"],
value="hero",
label="Character Type"
)
generate_character_btn = gr.Button("๐พ Generate Character", variant="primary")
with gr.Column():
character_output = gr.Textbox(label="Character Profile", lines=10)
with gr.TabItem("Level Design"):
with gr.Row():
with gr.Column():
level_description = gr.Textbox(
label="Level Description",
placeholder="Describe your game level...",
lines=4
)
level_type = gr.Dropdown(
choices=["dungeon", "outdoor", "city", "space", "underwater"],
value="dungeon",
label="Environment Type"
)
generate_level_btn = gr.Button("๐บ๏ธ Generate Level", variant="primary")
with gr.Column():
level_output = gr.Textbox(label="Level Design", lines=10)
def _create_science_research_interface(self):
"""Create science and research interface"""
gr.Markdown("## ๐ฌ Scientific research and analysis tools")
with gr.Tabs():
with gr.TabItem("Research Writing"):
with gr.Row():
with gr.Column():
research_model_dropdown = gr.Dropdown(
choices=[model.name for model in self.models.SCIENCE_RESEARCH_MODELS],
value="SciBERT",
label="Research Model"
)
research_topic = gr.Textbox(
label="Research Topic",
placeholder="Enter your research topic...",
lines=3
)
research_type = gr.Dropdown(
choices=["abstract", "introduction", "methodology", "discussion", "conclusion"],
value="abstract",
label="Section Type"
)
generate_research_btn = gr.Button("๐ Generate Research Content", variant="primary")
with gr.Column():
research_output = gr.Textbox(label="Research Content", lines=12)
with gr.TabItem("Data Analysis"):
with gr.Row():
with gr.Column():
data_file = gr.File(label="Upload Data File", file_types=[".csv", ".xlsx", ".json"])
analysis_type = gr.Dropdown(
choices=["descriptive", "statistical", "predictive", "clustering"],
value="descriptive",
label="Analysis Type"
)
analyze_data_btn = gr.Button("๐ Analyze Data", variant="primary")
with gr.Column():
data_analysis_output = gr.JSON(label="Analysis Results")
def _create_business_tools_interface(self):
"""Create business tools interface"""
gr.Markdown("## ๐ผ Professional business content generation")
with gr.Tabs():
with gr.TabItem("Email Generation"):
with gr.Row():
with gr.Column():
email_type = gr.Dropdown(
choices=["formal", "casual", "marketing", "follow_up", "invitation"],
value="formal",
label="Email Type"
)
email_context = gr.Textbox(
label="Email Context",
placeholder="Provide context for the email...",
lines=4
)
email_tone = gr.Dropdown(
choices=["professional", "friendly", "urgent", "persuasive"],
value="professional",
label="Tone"
)
generate_email_btn = gr.Button("๐ง Generate Email", variant="primary")
with gr.Column():
email_output = gr.Textbox(label="Generated Email", lines=10)
with gr.TabItem("Report Generation"):
with gr.Row():
with gr.Column():
report_type = gr.Dropdown(
choices=["quarterly", "annual", "project", "analysis", "summary"],
value="project",
label="Report Type"
)
report_data = gr.Textbox(
label="Report Data/Context",
placeholder="Provide data or context for the report...",
lines=6
)
generate_report_btn = gr.Button("๐ Generate Report", variant="primary")
with gr.Column():
report_output = gr.Textbox(label="Generated Report", lines=15)
|