acecalisto3 commited on
Commit
71d1038
·
verified ·
1 Parent(s): 805f6b2

Update appaaa.py

Browse files
Files changed (1) hide show
  1. appaaa.py +178 -30
appaaa.py CHANGED
@@ -352,33 +352,181 @@ async def respond(
352
  # Handle other commands or provide a default response
353
  yield "I'm not sure what you mean. Try using `/help` for a list of available commands."
354
 
355
- # Gradio Interface
356
- iface = gr.Interface(
357
- fn=respond,
358
- inputs=[
359
- gr.Textbox(label="Command", lines=1),
360
- gr.State(label="Chat History", value=[]),
361
- gr.Textbox(label="System Message", lines=1, value="You are a helpful and informative AI assistant."),
362
- gr.Slider(label="Max Tokens", minimum=1, maximum=1000, value=500, step=1),
363
- gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.7, step=0.1),
364
- gr.Slider(label="Top-p", minimum=0.0, maximum=1.0, value=0.9, step=0.1),
365
- gr.Textbox(label="GitHub API Token", lines=1, placeholder="Enter your GitHub API token"),
366
- gr.Textbox(label="GitHub Username", lines=1, placeholder="Enter your GitHub username"),
367
- gr.Textbox(label="GitHub Repository", lines=1, placeholder="Enter your GitHub repository"),
368
- gr.Dropdown(label="Model", choices=["text-davinci-003", "text-curie-001", "text-babbage-001", "text-ada-001"], value="text-davinci-003"),
369
- gr.Dropdown(label="Severity", choices=["Low", "Medium", "High"], value="Medium"),
370
- gr.Dropdown(label="Programming Language", choices=["Python", "JavaScript", "Java", "C++", "C#"], value="Python"),
371
- ],
372
- outputs=gr.Textbox(label="Response"),
373
- title="AI Assistant",
374
- description="Ask me anything, or use commands to interact with GitHub.",
375
- examples=[
376
- "/generate Create a REST API with FastAPI",
377
- "/analyze Memory leak in data processing pipeline",
378
- "/github octocat hello-world ghp_12345",
379
- "/list_issues"
380
- ],
381
- inputs=[chat.textbox] # Point to chat input instead of model selector
382
- )
383
-
384
- iface.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  # Handle other commands or provide a default response
353
  yield "I'm not sure what you mean. Try using `/help` for a list of available commands."
354
 
355
+
356
+
357
+ def create_gradio_interface():
358
+ def process_command(
359
+ command: str,
360
+ system_message: str,
361
+ max_tokens: int,
362
+ temperature: float,
363
+ top_p: float,
364
+ github_token: str,
365
+ github_username: str,
366
+ github_repo: str,
367
+ model: str,
368
+ severity: str,
369
+ programming_language: str
370
+ ):
371
+ try:
372
+ # Convert the synchronous call to async
373
+ import asyncio
374
+ return asyncio.run(respond(
375
+ command=command,
376
+ history=[],
377
+ system_message=system_message,
378
+ max_tokens=max_tokens,
379
+ temperature=temperature,
380
+ top_p=top_p,
381
+ github_api_token=github_token,
382
+ github_username=github_username,
383
+ github_repository=github_repo,
384
+ selected_model=model,
385
+ severity=severity,
386
+ programming_language=programming_language
387
+ ))
388
+ except Exception as e:
389
+ return f"Error: {str(e)}"
390
+
391
+ # Create the Gradio interface
392
+ with gr.Blocks(title="AI Assistant") as demo:
393
+ gr.Markdown("""
394
+ # AI Assistant
395
+ Ask me anything, or use commands to interact with GitHub.
396
+
397
+ Available commands:
398
+ - `/github <username> <repo> <token>`: Connect to GitHub
399
+ - `/help`: Show help
400
+ - `/generate_code`: Generate code
401
+ - `/analyze`: Analyze issues
402
+ - `/list_issues`: List repository issues
403
+ """)
404
+
405
+ with gr.Row():
406
+ with gr.Column():
407
+ command_input = gr.Textbox(
408
+ label="Command",
409
+ placeholder="Enter command (e.g., /help)",
410
+ lines=2
411
+ )
412
+
413
+ system_message = gr.Textbox(
414
+ label="System Message",
415
+ value="You are a helpful AI assistant.",
416
+ lines=2
417
+ )
418
+
419
+ with gr.Column():
420
+ github_token = gr.Textbox(
421
+ label="GitHub Token",
422
+ type="password",
423
+ placeholder="Enter GitHub token"
424
+ )
425
+ github_username = gr.Textbox(
426
+ label="GitHub Username",
427
+ placeholder="Enter GitHub username"
428
+ )
429
+ github_repo = gr.Textbox(
430
+ label="GitHub Repository",
431
+ placeholder="Enter repository name"
432
+ )
433
+
434
+ with gr.Row():
435
+ with gr.Column():
436
+ model = gr.Dropdown(
437
+ label="Model",
438
+ choices=["zephyr-7b-beta"],
439
+ value="zephyr-7b-beta"
440
+ )
441
+ severity = gr.Dropdown(
442
+ label="Severity",
443
+ choices=["Low", "Medium", "High"],
444
+ value="Medium"
445
+ )
446
+ programming_language = gr.Dropdown(
447
+ label="Programming Language",
448
+ choices=["Python", "JavaScript", "Java", "C++", "C#"],
449
+ value="Python"
450
+ )
451
+
452
+ with gr.Column():
453
+ max_tokens = gr.Slider(
454
+ label="Max Tokens",
455
+ minimum=50,
456
+ maximum=1000,
457
+ value=500,
458
+ step=50
459
+ )
460
+ temperature = gr.Slider(
461
+ label="Temperature",
462
+ minimum=0.1,
463
+ maximum=1.0,
464
+ value=0.7,
465
+ step=0.1
466
+ )
467
+ top_p = gr.Slider(
468
+ label="Top-p",
469
+ minimum=0.1,
470
+ maximum=1.0,
471
+ value=0.9,
472
+ step=0.1
473
+ )
474
+
475
+ submit_btn = gr.Button("Submit")
476
+ response_output = gr.Textbox(
477
+ label="Response",
478
+ lines=10,
479
+ placeholder="Response will appear here..."
480
+ )
481
+
482
+ # Handle submit button click
483
+ submit_btn.click(
484
+ fn=process_command,
485
+ inputs=[
486
+ command_input,
487
+ system_message,
488
+ max_tokens,
489
+ temperature,
490
+ top_p,
491
+ github_token,
492
+ github_username,
493
+ github_repo,
494
+ model,
495
+ severity,
496
+ programming_language
497
+ ],
498
+ outputs=response_output
499
+ )
500
+
501
+ # Add example commands
502
+ gr.Examples(
503
+ examples=[
504
+ ["/help", "You are a helpful AI assistant.", 500, 0.7, 0.9, "", "", "", "zephyr-7b-beta", "Medium", "Python"],
505
+ ["/github octocat hello-world YOUR_TOKEN", "You are a helpful AI assistant.", 500, 0.7, 0.9, "", "", "", "zephyr-7b-beta", "Medium", "Python"],
506
+ ["/generate_code Create a FastAPI REST API", "You are a helpful AI assistant.", 500, 0.7, 0.9, "", "", "", "zephyr-7b-beta", "Medium", "Python"],
507
+ ],
508
+ inputs=[
509
+ command_input,
510
+ system_message,
511
+ max_tokens,
512
+ temperature,
513
+ top_p,
514
+ github_token,
515
+ github_username,
516
+ github_repo,
517
+ model,
518
+ severity,
519
+ programming_language
520
+ ]
521
+ )
522
+
523
+ return demo
524
+
525
+ # Launch the interface
526
+ if __name__ == "__main__":
527
+ demo = create_gradio_interface()
528
+ demo.launch(
529
+ server_name="0.0.0.0",
530
+ server_port=7860,
531
+ share=False
532
+ )