Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Example API key setup (for testing)
|
| 7 |
+
openai.api_key = "YOUR_API_KEY"
|
| 8 |
+
|
| 9 |
+
def evaluate_prompt(model_name, prompt_text):
|
| 10 |
+
"""
|
| 11 |
+
Runs a single evaluation against OpenAI or Anthropic API
|
| 12 |
+
Returns text output and token count
|
| 13 |
+
"""
|
| 14 |
+
if model_name.lower() == "gpt-4":
|
| 15 |
+
response = openai.ChatCompletion.create(
|
| 16 |
+
model="gpt-4",
|
| 17 |
+
messages=[{"role":"user","content":prompt_text}],
|
| 18 |
+
temperature=0.5
|
| 19 |
+
)
|
| 20 |
+
output_text = response['choices'][0]['message']['content']
|
| 21 |
+
tokens = response['usage']['total_tokens']
|
| 22 |
+
return f"Output:\n{output_text}\n\nTokens used: {tokens}"
|
| 23 |
+
else:
|
| 24 |
+
return "Model not supported yet"
|
| 25 |
+
|
| 26 |
+
# Gradio UI
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("## MotionEval: AI Model Evaluation MVP")
|
| 29 |
+
|
| 30 |
+
model_name = gr.Textbox(label="Model Name (e.g. GPT-4)")
|
| 31 |
+
prompt_text = gr.Textbox(label="Prompt", lines=5)
|
| 32 |
+
|
| 33 |
+
run_button = gr.Button("Run Evaluation")
|
| 34 |
+
output = gr.Textbox(label="Result", lines=15)
|
| 35 |
+
|
| 36 |
+
run_button.click(fn=evaluate_prompt, inputs=[model_name, prompt_text], outputs=output)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|