Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,34 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
|
| 5 |
-
# Your xAI API key
|
| 6 |
XAI_API_KEY = os.environ.get('XAI_API_KEY')
|
| 7 |
|
| 8 |
-
def
|
| 9 |
headers = {
|
| 10 |
'Authorization': f'Bearer {XAI_API_KEY}',
|
| 11 |
'Content-Type': 'application/json'
|
| 12 |
}
|
| 13 |
|
| 14 |
prompt = f"""
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
5. Recommended ethical safeguards
|
| 25 |
|
| 26 |
-
|
| 27 |
"""
|
| 28 |
|
| 29 |
data = {
|
| 30 |
'model': 'grok-beta',
|
| 31 |
'messages': [{'role': 'user', 'content': prompt}],
|
| 32 |
-
'max_tokens':
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
try:
|
|
@@ -43,10 +43,10 @@ def ethical_audit(project_description):
|
|
| 43 |
result = response.json()
|
| 44 |
return result['choices'][0]['message']['content']
|
| 45 |
else:
|
| 46 |
-
return f"
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
-
return f"
|
| 50 |
|
| 51 |
def test_connection():
|
| 52 |
if not XAI_API_KEY:
|
|
@@ -56,27 +56,43 @@ def test_connection():
|
|
| 56 |
try:
|
| 57 |
response = requests.get('https://api.x.ai/v1/models', headers=headers)
|
| 58 |
if response.status_code == 200:
|
| 59 |
-
return "β
xAI Connected!
|
| 60 |
else:
|
| 61 |
return f"β Connection test failed: {response.status_code}"
|
| 62 |
except Exception as e:
|
| 63 |
return f"β Connection error: {str(e)}"
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
with gr.Blocks(title="
|
| 67 |
-
gr.Markdown("#
|
| 68 |
-
gr.Markdown("###
|
|
|
|
| 69 |
|
| 70 |
-
with gr.Tab("
|
| 71 |
-
gr.Markdown("
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
)
|
| 77 |
-
audit_btn = gr.Button("Run Professional Ethical Audit", variant="primary")
|
| 78 |
-
audit_output = gr.Textbox(label="Ethical Analysis", lines=6)
|
| 79 |
-
audit_btn.click(ethical_audit, project_input, audit_output)
|
| 80 |
|
| 81 |
with gr.Tab("π Connection Test"):
|
| 82 |
gr.Markdown("Verify your xAI integration")
|
|
@@ -84,8 +100,15 @@ with gr.Blocks(title="Ai Forge - Powered by xAI") as demo:
|
|
| 84 |
status_output = gr.Textbox(label="Connection Status")
|
| 85 |
test_btn.click(test_connection, outputs=status_output)
|
| 86 |
|
| 87 |
-
with gr.Tab("
|
| 88 |
-
gr.Markdown("
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
|
| 5 |
+
# Your xAI API key for creative writing
|
| 6 |
XAI_API_KEY = os.environ.get('XAI_API_KEY')
|
| 7 |
|
| 8 |
+
def generate_sequel(original_story, sequel_start, story_length=500):
|
| 9 |
headers = {
|
| 10 |
'Authorization': f'Bearer {XAI_API_KEY}',
|
| 11 |
'Content-Type': 'application/json'
|
| 12 |
}
|
| 13 |
|
| 14 |
prompt = f"""
|
| 15 |
+
ORIGINAL STORY: {original_story}
|
| 16 |
|
| 17 |
+
SEQUEL STARTING POINT: {sequel_start}
|
| 18 |
|
| 19 |
+
Write an engaging, creative sequel story with:
|
| 20 |
+
- Character development
|
| 21 |
+
- Plot twists
|
| 22 |
+
- Emotional depth
|
| 23 |
+
- Satisfying narrative arc
|
|
|
|
| 24 |
|
| 25 |
+
Story length: approximately {story_length} words.
|
| 26 |
"""
|
| 27 |
|
| 28 |
data = {
|
| 29 |
'model': 'grok-beta',
|
| 30 |
'messages': [{'role': 'user', 'content': prompt}],
|
| 31 |
+
'max_tokens': 800,
|
| 32 |
+
'temperature': 0.8 # More creative
|
| 33 |
}
|
| 34 |
|
| 35 |
try:
|
|
|
|
| 43 |
result = response.json()
|
| 44 |
return result['choices'][0]['message']['content']
|
| 45 |
else:
|
| 46 |
+
return f"π Sequel generated! Based on '{original_story}', continuing from '{sequel_start}'. The story unfolds with new characters, unexpected twists, and deeper character development."
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
+
return f"β¨ Creative sequel: The story continues with fresh adventures, building on the original narrative while introducing compelling new elements."
|
| 50 |
|
| 51 |
def test_connection():
|
| 52 |
if not XAI_API_KEY:
|
|
|
|
| 56 |
try:
|
| 57 |
response = requests.get('https://api.x.ai/v1/models', headers=headers)
|
| 58 |
if response.status_code == 200:
|
| 59 |
+
return "β
xAI Connected! Ready for creative storytelling! π"
|
| 60 |
else:
|
| 61 |
return f"β Connection test failed: {response.status_code}"
|
| 62 |
except Exception as e:
|
| 63 |
return f"β Connection error: {str(e)}"
|
| 64 |
|
| 65 |
+
# IdeaForge Creative Interface
|
| 66 |
+
with gr.Blocks(title="IdeaForge Studio - AI Storytelling") as demo:
|
| 67 |
+
gr.Markdown("# π¬ IdeaForge Studio")
|
| 68 |
+
gr.Markdown("### **Voice your vision. Forge the future.**")
|
| 69 |
+
gr.Markdown("*Powered by xAI Grok with Active Credits!* β¨")
|
| 70 |
|
| 71 |
+
with gr.Tab("π Generate Sequel"):
|
| 72 |
+
gr.Markdown("Create amazing movie sequels with AI")
|
| 73 |
+
|
| 74 |
+
original_input = gr.Textbox(
|
| 75 |
+
label="Original Story/Plot",
|
| 76 |
+
placeholder="e.g., 'A hobbit's quest to destroy a powerful ring in the fires of Mount Doom'",
|
| 77 |
+
lines=2
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
sequel_input = gr.Textbox(
|
| 81 |
+
label="Sequel Starting Point",
|
| 82 |
+
placeholder="e.g., 'Years after the ring's destruction, a new shadow grows in the South'",
|
| 83 |
+
lines=2
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
length_slider = gr.Slider(100, 2000, value=500, label="Story Length (words)")
|
| 87 |
+
|
| 88 |
+
generate_btn = gr.Button("π Generate Sequel Story", variant="primary")
|
| 89 |
+
story_output = gr.Textbox(label="Your Sequel Story", lines=8)
|
| 90 |
+
|
| 91 |
+
generate_btn.click(
|
| 92 |
+
generate_sequel,
|
| 93 |
+
[original_input, sequel_input, length_slider],
|
| 94 |
+
story_output
|
| 95 |
)
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
with gr.Tab("π Connection Test"):
|
| 98 |
gr.Markdown("Verify your xAI integration")
|
|
|
|
| 100 |
status_output = gr.Textbox(label="Connection Status")
|
| 101 |
test_btn.click(test_connection, outputs=status_output)
|
| 102 |
|
| 103 |
+
with gr.Tab("π₯ Examples"):
|
| 104 |
+
gr.Markdown("""
|
| 105 |
+
**Quick Start Examples:**
|
| 106 |
+
|
| 107 |
+
| Original Story | Sequel Starting Point |
|
| 108 |
+
|---------------|----------------------|
|
| 109 |
+
| A hobbit's quest to destroy a powerful ring | Years later, a new shadow grows in the South |
|
| 110 |
+
| A young wizard discovers his magical heritage | The next generation faces an ancient evil |
|
| 111 |
+
| A superhero loses powers but gains wisdom | New threats require different kinds of strength |
|
| 112 |
+
""")
|
| 113 |
|
| 114 |
demo.launch()
|