Created
November 21, 2025 06:19
-
-
Save zainhas/dccd9484c98489fa9529f25b728d9cc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fastapi_poe as fp | |
| import os | |
| import sseclient | |
| import json | |
| from fastapi_poe import make_app | |
| from together import Together | |
| import requests | |
| import constants | |
| import pillow_heif | |
| from PIL import Image | |
| import io | |
| import base64 | |
| TOGETHER_API_KEY = os.environ["TOGETHER_API_KEY"] | |
| client = Together() | |
| class TogetherTranscribeBot2(fp.PoeBot): | |
| def __init__(self, model_url, path=None): | |
| super().__init__(path=path) | |
| self.model_url = model_url | |
| async def get_response(self, request: fp.QueryRequest): | |
| try: | |
| message = request.query[-1] | |
| print("MESSAGE IS: ", message) | |
| if not message.attachments or not message.attachments[ | |
| -1 | |
| ].content_type.startswith("audio"): | |
| yield fp.ErrorResponse( | |
| text="This bot needs an audio file to transcribe.", | |
| error_type="user_caused_error", | |
| ) | |
| return | |
| audioFile = message.attachments[-1].url | |
| timestamp_option = message.parameters.get("timestamp_granularities", "none") | |
| transcription_params = { | |
| "file": audioFile, | |
| "model": self.model_url, | |
| } | |
| if timestamp_option == "word": | |
| transcription_params["timestamp_granularities"] = ["word"] | |
| transcription_params["response_format"] = "verbose_json" | |
| response = client.audio.transcriptions.create(**transcription_params) | |
| if timestamp_option == "word": | |
| yield fp.PartialResponse(text=f"{json.dumps(response.model_dump()['words'], indent=2)}") | |
| else: | |
| yield fp.PartialResponse(text=f"{response.text}") | |
| except requests.exceptions.HTTPError as e: | |
| print(f"HTTP Error occurred: {e}") | |
| print(f"Response content: {e.response.content}") | |
| raise | |
| async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse: | |
| """Return the settings for this bot.""" | |
| return fp.SettingsResponse( | |
| allow_attachments=True, | |
| parameter_controls=fp.ParameterControls( | |
| api_version="2", | |
| sections=[ | |
| fp.Section( | |
| name="Transcription Options", | |
| controls=[ | |
| fp.DropDown( | |
| label="Timestamp Granularities", | |
| description="Include word-level timestamps in transcription output (JSON format)", | |
| parameter_name="timestamp_granularities", | |
| default_value="none", | |
| options=[ | |
| fp.ValueNamePair(name="None", value="none"), | |
| fp.ValueNamePair(name="Word", value="word"), | |
| ], | |
| ), | |
| ], | |
| ) | |
| ] | |
| ), | |
| ) | |
| bots = [ | |
| TogetherTranscribeBot2( | |
| model_url="openai/whisper-large-v3", | |
| path="/testwhisper", | |
| ), | |
| ] | |
| app = make_app(bots, allow_without_key=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment